C#-RegisterClientScriptBlock的无用错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#-RegisterClientScriptBlock的无用错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1711字,纯文字阅读大概需要3分钟。
内容图文
![C#-RegisterClientScriptBlock的无用错误](/upload/InfoBanner/zyjiaocheng/675/6f5bd9ea5a8445b8a2fe7bbeda09a307.jpg)
当用户进入网格视图上的编辑模式时,我正在使用RegisterClientScriptBlock向用户发送JS警报,但是由于某种原因,这导致我的页面出错,我无法弄清原因…
这是导致问题的方法.错误发生在注册脚本的最后一行. (如果我对此发表评论,则该页面效果很好!)
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
gvStockItems.EditIndex = e.NewEditIndex;
// Gather current Search info
string strPartNo = Session["currentSearchTerm"].ToString();
BindData();
gvStockItems.SelectedIndex = gvStockItems.EditIndex;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "thisIsTest", "<script language=\"text/javascript\">alert(\"oops\");</script>");
}
JS控制台中引发的错误是
Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
它还说此错误发生在ScriptResource.axd的Error $Create中,但是我认为这是在报告真正问题所在时发生的错误,因此我很困惑.
任何帮助是极大的赞赏.谢谢.
解决方法:
删除Page.ClientScript.RegisterClientScriptBlock并尝试使用RegisterStartupScript
// Define the name and type of the client scripts on the page.
String csname1 = "thisIsTest";
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))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('oops!') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
或者,如果您有ScriptManager,则
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisIsTest", "alert('oops!');", true);
内容总结
以上是互联网集市为您收集整理的C#-RegisterClientScriptBlock的无用错误全部内容,希望文章能够帮你解决C#-RegisterClientScriptBlock的无用错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。