protected void Button1_Click(object sender, EventArgs e)
{
if (bittext.Text == "")
Response.Write("<script>alert('Enter The value first or press the correct button')</script>");
else
{
b = double.Parse(bittext.Text);
Bytetext.Text = (b / 8).ToString();
kbtext.Text = (b / 8192).ToString();
mbtext.Text = (b / 8388608).ToString();
gbtext.Text = (b / 8589934592).ToString();
tbtext.Text = (b / 8796093022000).ToString();
}
}
如果我运行此 Web C# 代码而不在 bittext.Text 中输入任何内容,则会引发名为:
的错误Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
我该如何解决这个问题?
最佳答案
您不能为此使用Response.Write()
,您需要 ScriptManager.RegisterStartupScript
,像这样:
ScriptManager.RegisterStartupScript(this, GetType(), "alert",
"alert('Enter The value first or press the correct button');", true);
Response.Write()
只是在响应中转储该脚本标记,这会在客户端解析它时产生无效/意外的格式,您希望正确执行一个片段JavaScript...上面是正确/提供的机制。
关于javascript - Microsoft JScript 运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4213461/