aspx.net ajax 1.0 问题

UpdatePanel里不要使用Response.Write()来弹出js代码,会出错.
要这样处理
ScriptManager.RegisterStartupScript(Control,type,Key,Script,bool)

ScriptManager.RegisterStartupScript(this.UpdatePanel1,this.GetType(), "mq", "alert('The page has loaded!')",true); 

这样代码运行到这里就能弹出对话框了.


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);


引用: http://blog.csdn.net/ccp5780199/archive/2007/09/21/1794233.aspx

你可能感兴趣的:(.net)