[英]ASP.net fails to RegisterClientScriptBlock
When I try to register this script in my trace it says it is not registered Even though I exclaim its registration here: 当我尝试在跟踪中注册该脚本时,它表示未注册,尽管我在这里大声疾呼它的注册:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DrillThrough report " + (int) dr["ReportID"] + " script", vbs_script);
The scripts file name is DrillThrough6-0.Function.BT.SS2005.ReportID42193.vbs
What could be going wrong. 脚本文件名为
DrillThrough6-0.Function.BT.SS2005.ReportID42193.vbs
可能出了问题。 Plus if I run Internet explorer using developer tools(maybe just a coincidence, but it constantly happens only with developer tools on) it registers fine. 另外,如果我使用开发人员工具运行Internet Explorer(也许只是一个巧合,但仅在使用开发人员工具的情况下经常发生),它的注册情况就很好。 And runs as its suppose to otherwise it doesn't run at all.
并以其假定的方式运行,否则根本不运行。
Code for Context: 上下文代码:
SqlDataReader dr = PivotTableDB.GetReport(drillThroughReportID);
Trace.Warn("Attempting to Read... ");
if (dr.Read()) {
Trace.Warn("Reading... ");
Page.ClientScript.RegisterHiddenField("txt_DetailReportCubeName", (string) dr["CubeName"]);
string path = (string) this.MapPath("~/DesktopModules/PivotTableNav/DrillThroughReportScripts/");
string name = (string) dr["DisplayName_en"] + ".ReportID" + (int) dr["ReportID"] + ".vbs";
string vbs_script = "";
if (File.Exists(path + name)) {
StreamReader sr = new StreamReader(path + name,System.Text.Encoding.GetEncoding("iso-8859-1"));
vbs_script = sr.ReadToEnd();
vbs_script = vbs_script.Replace("Spreadsheet1","document.Form1.Spreadsheet1");
vbs_script = vbs_script.Replace("for=document.Form1.Spreadsheet1","for=Spreadsheet1");
sr.Close();
}
if (vbs_script != null) {
Trace.Warn("vbscript", vbs_script);
Trace.Warn("vbscript-path", (path + name));
Trace.Warn("vbscriptExist", "File exist: " + File.Exists(path + name) + " BlockRegistered already: " + Page.ClientScript.IsClientScriptBlockRegistered("DrillThrough report " + (int)dr["ReportID"] + " script"));
if (! Page.ClientScript.IsClientScriptBlockRegistered("DrillThrough report " + (int) dr["ReportID"] + " script"))
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DrillThrough report " + (int) dr["ReportID"] + " script", vbs_script);
}
Trace.Warn("Was vbscript Registered: " + Page.ClientScript.IsClientScriptBlockRegistered("DrillThrough report " + (int)dr["ReportID"] + " script"));
Title.Text = LanguageUtils.ChooseOnLanguage(dr["DisplayName_en"].ToString(), dr["DisplayName_fr"].ToString());
}
else { Trace.Warn("Did not read the report since no data no rows: "); }
dr.Close();
To get this to work i changed RegisterClientScriptBlock to RegisterStartupScript. 为了使它起作用,我将RegisterClientScriptBlock更改为RegisterStartupScript。 And now the register is successful , obivious change isClientScriptBlockRegistered to the IsStartupScriptRegistered.
现在注册成功了,显而易见的是将isClientScriptBlockRegistered更改为IsStartupScriptRegistered。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.