您的位置:首页 > 编程语言 > ASP

从 ASP.NET 服务器控件插入客户端脚本

2005-03-16 23:07 489 查看
http://www.microsoft.com/china/MSDN/library/archives/library/DNAspp/html/aspnet-injectclientsidesc.asp
(1)动态改变<asp:Button>外观
  <asp:Button id="Button1"onmouseout="this.style.backgroundColor='blue'"        onmouseover="this.style.backgroundColor='red'" runat="server" />
(2)脚本检验数据
   一、在页面中写上javascript的函数:
       <script language=javascript>
            function test(){
               alert("this is test!!");
            }
            function test2(){
               var state = confirm("是否删除?");
               return state;
               }
       </scirpt>
   二、在后置文件中的Page_Load()事件中邦定控件
       Button1.Attributes.Add("onclick","javascript:return test();");
  
   三、让<ASP:TextBox …… /> 获得焦点
        1.document.getElementById("myTextBox").focus();
        2.document.myForm1.myTextBox.focus();

   四、Page.RegisterStartupScript(key,script)
           允许ASP.NET服务器控件在System.Web.UI.Page中发出客户脚本块。
           key是运行时脚本的一个文本索引;script表示客户端脚本的正文文本。
           string str="<scr"+"ipt> alert('"+parReason.Value.ToString() + "');</scr"+"ipt>";
           this.RegisterStartupScript("reason",str);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息