当前位置: 代码迷 >> ASP.NET >> 请教 怎么在后台给 <body> 增加客户端事件 例如:<body onload="alert('')"
  详细解决方案

请教 怎么在后台给 <body> 增加客户端事件 例如:<body onload="alert('')"

热度:8418   发布时间:2013-02-25 00:00:00.0
请问 如何在后台给 <body>, 增加客户端事件 例如:<body onload="alert('')"
请问   如何在后台给   <body> ,     增加客户端事件     例如: <body   onload= "alert( ' ') "

------解决方案--------------------------------------------------------
sorry for my misunderstanding :)

MasterPage.master-
<body runat= "server " id= "body ">
<form id= "form1 " runat= "server ">
<div>
<asp:contentplaceholder id= "ContentPlaceHolder1 " runat= "server ">
</asp:contentplaceholder>
</div>
</form>
</body>

Default.aspx-
<%@ Page Language= "C# " MasterPageFile= "~/MasterPage.master " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>

<asp:Content ID= "content1 " runat= "server " ContentPlaceHolderID= "ContentPlaceHolder1 ">
</asp:Content>

Default.aspx.cs-
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), " ", " <script> document.getElementById( 'ctl00_body ').onload =function(){alert( 'liuliu ');} </script> ");
}
  相关解决方案