ClientScriptManager.RegisterStartupScript的使用
来源:互联网 发布:大数据及可视化技术 编辑:程序博客网 时间:2024/05/22 00:27
因为ClientScriptManager是一个密封类,因为平时编程中很少用到密封类,一时用常规的思维去使用,不成功,
的使用,后来我查了msdn,ClientScriptManager cs = Page.ClientScript; 但是密封类还和常规类一样的使用方法只是这个类没有构造函数,不能按照常规方法使用。
public void Page_Load(Object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
String csname2 = "ButtonClickScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "alert('Hello World');";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type="text/javascript"> function DoClick() {");
cstext2.Append("Form1.Message.value='Text from client script.'} </");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
String csname2 = "ButtonClickScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "alert('Hello World');";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type="text/javascript"> function DoClick() {");
cstext2.Append("Form1.Message.value='Text from client script.'} </");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}
- ClientScriptManager.RegisterStartupScript的使用
- ScriptManager.RegisterStartupScript()的使用
- Page.ClientScript.RegisterStartupScript 的使用
- ,ClientScriptManager.RegisterForEventValidation 的问题
- Asp.net中RegisterStartupScript方法的使用
- RegisterClientScriptBlock 与 RegisterStartupScript的使用与区别
- Asp.net中RegisterStartupScript方法的使用
- RegisterClientScriptBlock 与 RegisterStartupScript的使用与区别
- RegisterStartupScript 使用误区
- RegisterStartupScript 使用误区
- 使用Page.ClientScript.RegisterStartupScript
- RegisterStartupScript,RegisterClientScriptBlock使用
- ASP.NET2.0中ClientScriptManager的用法(使用ASP.NET 2.0 AJAX 弹出对话框)
- 使用ClientScriptManager向客户端注册脚本
- 使用ClientScriptManager向客户端注册脚本
- 使用ClientScriptManager向客户端注册脚本
- 使用ClientScriptManager向客户端注册脚本
- RegisterStartupScript的使用方法
- c# xml操作类
- OpenCms7.0.3为我们“带来/修正”了些什么?
- 【转贴】16个经典面试问题回答思路
- 基于小波变换的图像压缩技术初探
- 头疼医头,脚疼医脚
- ClientScriptManager.RegisterStartupScript的使用
- 修改oracle servlet engine默认端口
- [英语歌曲]只有爱:Only love
- 大家好!
- KMP
- 最近物价上涨,工资没有涨,烦啊
- Delphi中资源文件的使用
- IBM拟50亿美元收购商业智能软件厂商Cognos
- Internationalization in JSF and JSTL