UpdatePanel使用脚本
其实就一句话的事
ScriptManager.RegisterStartupScript(this.UpdatePanel1,this.GetType(), "HelloWorld", "alert('The page has loaded!')",true);
再次强调在UpdatePanel里不要使用Response.Write();
另.NET 2.0中调用脚本的几个方法
方法名 | 用途 | 示例 |
RegisterArrayDeclaration | 创建JavaScript数组 | ScriptManager.RegisterArrayDeclaration(UpdatePanel1,"Hello", ,"1,2,3"); |
RegisterClientScriptBlock | 为对象输出一个函数,为true时自动加上<script></script> | ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "HelloWorld", "function helloWorld(){alert(1);}", true); |
RegisterClientScriptInclude | 添加对脚本文件的引用 | ScriptManager.RegisterClientScriptInclude(UpdatePanel1,this.GetType(), "HelloWorld",Server.MapPath("test.js")); |
RegisterClientScriptResource | 访问程序集中的脚本文件 | ScriptManager.RegisterClientScriptResource(UpdatePanel1,this.GetType(), "test.js"); |
RegisterExpandoAttribute | 为指定控件添加额外的属性 | ScriptManager.RegisterExpandoAttribute(UpdatePanel1,Button1.ClientID, "attributeName","attributeValue",true);
|
RegisterHiddenField | 添加个隐藏值 | ScriptManager.RegisterHiddenField(UpdatePanel1, "hiddenFieldName", "hiddenFieldIntialValue"); |
RegisterOnSubmitStatement | 提交的Confirm | ScriptManager.RegisterOnSubmitStatement(UpdatePanel1,this.GetType(), "test", "return window.confirm('test')"); |
RegisterStartupScript | 添加一个最开始运行的脚本 | ScriptManager.RegisterStartupScript(UpdatePanel1,this.GetType(), "HelloWorld", "alert('The page has loaded!')",true); |