Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->网站设计 ->AJAX教程 ->正文

关天asp.net ajax beta中在updatepnael中注册脚本的解决方案

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-04 点击: [收藏] [投稿]

最近也在看一些asp.net ajax 的资料,在网上看到很多人都在问如何在updatepanel中注册脚本,我也试了一下,不过总是不行,就看了好多资料,最后才知道自己没有完全理解 ScriptManager.RegisterClientScriptBlock(Control control,Type type,string key, string script,bool addScriptTags),其中的各个参数。(注:RegisterClientScriptBlock是 ScriptManager的一个静态方法)
          参数详解:
                           control (Control) :这个参数是注册脚本块的控件.如果你是在updatepanel中注册时,即updatepanel  (应该写updatepanel的ID).
                            type (Type)        :这个参数是注册脚本块控件的类型,即updatepanel的类型。
                           key (String)         :这个参数是脚本酷块的惟一标识(关键字)
                           script (String)      :这个参数是要注册的脚本字符串.
                         addScriptTags (Boolean) :这个参数表示是否要在您的字符串两边使用“<script>”和“</script>”包围起来.

然后这是我写的一个简单的例子:
               
  Html代码:
                                  <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <link href="/aspnet_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/css/default.css"
        rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1"   runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

CS代码:
    protected void Button1_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "test", "alert('test');", true);

    }

     以上是我的理解,如果有不正确的地方,请大家纠正,我先放到首页,其实没有什么技术含量,主要是用来让那些还不知道如何注册的朋友看到.过后dohu可以删了。
http://www.cnblogs.com/sunlife/archive/2006/11/05/550520.html



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:ajax和asp.net的配置文件   下一篇:ASP.NET AJAX Beta2 调用本地WebService的一些改变

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号