关于应用AspncPostBackError事件,来让浏览器报错。引发一个除数为0的异常,代码有执行,没有语法错误,但是浏览器没有反应,不能提示错误信息。调试的时候编译也会提示有异常,高手帮帮小弟。 protected void Button1_Click(object sender, EventArgs e)
{
int a = Int32.Parse(TextBox1.Text);
int b = Int32.Parse(TextBox2.Text);
try
{
if(DropDownList1 .SelectedValue =="+")
TextBox3 .Text = (a + b).ToString ();
if (DropDownList1.SelectedValue == "-")
TextBox3.Text = (a - b).ToString();
if (DropDownList1.SelectedValue == "*")
TextBox3.Text = (a * b).ToString();
else if (DropDownList1.SelectedValue == "/")
TextBox3.Text = (a / b).ToString();
}
catch (Exception ex)
{
if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
{
ex.Data["ExtraInfo"] = " 不能将 " +
TextBox1.Text + "除以" + TextBox2.Text + ".";
}
throw ex;
}
}
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
if (e.Exception.Data["ExtraInfo"] != null)
{
ScriptManager1.AsyncPostBackErrorMessage =
e.Exception.Message +
e.Exception.Data["ExtraInfo"].ToString();
}
else
{
ScriptManager1.AsyncPostBackErrorMessage =
"未指定的错误发.";
}
{
int a = Int32.Parse(TextBox1.Text);
int b = Int32.Parse(TextBox2.Text);
try
{
if(DropDownList1 .SelectedValue =="+")
TextBox3 .Text = (a + b).ToString ();
if (DropDownList1.SelectedValue == "-")
TextBox3.Text = (a - b).ToString();
if (DropDownList1.SelectedValue == "*")
TextBox3.Text = (a * b).ToString();
else if (DropDownList1.SelectedValue == "/")
TextBox3.Text = (a / b).ToString();
}
catch (Exception ex)
{
if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
{
ex.Data["ExtraInfo"] = " 不能将 " +
TextBox1.Text + "除以" + TextBox2.Text + ".";
}
throw ex;
}
}
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
if (e.Exception.Data["ExtraInfo"] != null)
{
ScriptManager1.AsyncPostBackErrorMessage =
e.Exception.Message +
e.Exception.Data["ExtraInfo"].ToString();
}
else
{
ScriptManager1.AsyncPostBackErrorMessage =
"未指定的错误发.";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货