再添加Label3后,,将错误显示给浏览者?

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:09:51
aspx.cs代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class plus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
int a = Int32.Parse(TextBox1.Text);
int b = Int32.Parse(TextBox2.Text);
int res = a / b;
Label2.Text = res.ToString();
}
catch (Exception ex)
{
if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
{

ex.Data["ExtraInfo"] = "You can't divide" + TextBox1.Text + "by" + TextBox2.Text;
这句你直接换成
Label3.Text=You can't divide" + TextBox1.Text + "by" + TextBox2.Text;

首先楼上做法可以:
Label3.Text=“You can't divide" + TextBox1.Text + " by "+ TextBox2.Text+“”;
第二我 想说的是:
if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
你不觉得你的判断条件一问题吗?TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0,你难道想它为空的时候正常而有值的时候抛异常吗?
我看你的判断条件应该是TextBox2.Text不为零,还有
TextBox1.Text和TextBox2.Text不为空啊