久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

asp.net中模板頁(yè)(母版頁(yè))中調(diào)用body的onload事件的方法

 glxym 2015-05-09
國(guó)外網(wǎng)站的方法


碰到有個(gè)繼承了母版頁(yè)的頁(yè)面要加載body的onload事件,,我發(fā)了一下午來(lái)解決這個(gè)問(wèn)題,,終于在國(guó)外某論壇上找到了解決方案

Method1:

In the master page make the body a control by giving the runat="server" attribute and a name.

<body runat="server" id="MyBody">

Next, use the following code in the Page_Load event of the page (Default.aspx or any other page which inherits from the master page).

HtmlGenericControl body = (HtmlGenericControl)
Page.Master.FindControl("MyBody");
body.Attributes.Add("onload", "alert('hello world')");

And, thats it! Now the body event is only generated for a particular page.

Method2:

Hi. It's a good solution! But try also my approach
1. in MasterPage create ContentPlaceHolder for just opening <body> tag:
<asp:contentplaceholder id="BodyPlaceHolder1" runat="server"><body></asp:contentplaceholder>

2. in your .aspx pages create specific content with onload event
<asp:Content ontentPlaceHolderID=BodyPlaceHolder1 runat=server>
<body onload="alert('hello');">
</asp:Content>


國(guó)內(nèi)的兩種實(shí)現(xiàn)方法



1.客戶(hù)端:

<script language="javascript" type="text/javascript">

window.onload=function getTime()
{
    var date = new Date(); //日期對(duì)象 
    var now = ""; 
    now = date.getFullYear()+"-"; //讀英文就行了 
    now = now + (date.getMonth()+1)+"-"; //取月的時(shí)候取的是當(dāng)前月-1如果想取當(dāng)前月+1就可以了 
    now = now + date.getDate();
    document.getElementById("txtAddDate").value=now;
}
</script>

2.服務(wù)器端:

protected override void Render(HtmlTextWriter writer)
     {
         //繼承模板頁(yè)的內(nèi)容頁(yè)加入 onload 事件
         System.IO.StringWriter sw = new System.IO.StringWriter();
         HtmlTextWriter htw = new HtmlTextWriter(sw);
         base.Render(htw);
         writer.Write(sw.ToString().Replace("<body", "<body onload=javascript:alert('歡迎光臨!');"));
     }





    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,,不代表本站觀(guān)點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多