首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Page.ClientScript.RegisterStartupScript没有反应解决方法

2012-02-08 
Page.ClientScript.RegisterStartupScript没有反应protectedvoidPage_Load(objectsender,EventArgse){stri

Page.ClientScript.RegisterStartupScript没有反应
protected   void   Page_Load(object   sender,   EventArgs   e)
{
      string   myScript   =   @ "alert(document.forms[0][ 'Label1 '].value;) ";

      Page.ClientScript.RegisterStartupScript(this.GetType(),   "MyScript ",   myScript,   true);            
}

<%@   Page   Language= "C# "   AutoEventWireup= "true "     CodeFile= "Default.aspx.cs "   Inherits= "_Default "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title   id= "Title1 "   runat= "server "> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                <asp:Label   ID= "Label1 "   runat= "server "   Text= "Label "> aaa </asp:Label>
                </div>
        </form>
</body>
</html>

------------------------------
执行后的HTML
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head> <title>
无标题页
</title> </head>
<body>
        <form   name= "form1 "   method= "post "   action= "Default.aspx "   id= "form1 ">
<div>
<input   type= "hidden "   name= "__VIEWSTATE "   id= "__VIEWSTATE "   value= "/wEPDwUKMTcyMTYyMjM5NmRkZdqwnR4d9teWOEPkUQTLVxGRQps= "   />
</div>

        <div>
                <span   id= "Label1 "> aaa </span>
                <input   type= "submit "   name= "Button1 "   value= "Button "   id= "Button1 "   /> </div>
       
<div>

<input   type= "hidden "   name= "__EVENTVALIDATION "   id= "__EVENTVALIDATION "   value= "/wEWAgL5mKTeAgKM54rGBvLIeDMJhguFT2LbZlAJJbn9It8H "   />
</div>

<script   type= "text/javascript ">
<!--
alert(document.forms[0][ 'Label1 '].value;)//   --> <!--行22,字符40-->
</script>
</form>
</body>
</html>
行22,字符40错误:缺少 ') '

[解决办法]
;应该写在)后面

热点排行