日期:2014-05-18  浏览次数:20489 次

动态添加脚本问题
在 <form> 之后添加OK,在 </form> 之前添加就不OK了,请问哪错了?


//.aspx   file

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

<!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> Add   Client   Event </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                <input   id= "Submit1 "   type= "submit "   value= "Click   me "   onclick= "Click() "   />
                </div>
               
        </form>
</body>
</html>


//.aspx.cs   file

using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;

public   partial   class   AddClientEvent   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                //MSDN:Page.RegisterClientScriptBlock   方法已被否决。请改用   ClientScriptManager   类的   RegisterClientScriptBlock   方法。

                ClientScriptManager   csm   =   Page.ClientScript;

                string   strScript1   =   "script1 ";
                string   strScript2   =   "script2 ";
                //OK
                if   ((!Page.IsPostBack)   &&   (!csm.IsClientScriptBlockRegistered(strScript1)))
                {
                        string   ss1   =   "alert( '在 <form> 标记之后 ') ";
                        csm.RegisterClientScriptBlock(this.GetType(),   strScript1,   ss1,   true);
                }
                //Error
                if   ((!Page.IsPostBack)   &&   (!csm.IsStartupScriptRegistered(strScript2)))
                {