在ASP.NET下用VS2008写了一段程序实现页面传值功能:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
this.TextBox1.Enabled = false;//如是首次加载则把Textbox1置为不可编辑
}
else
if(!IsPostBack)
{
_Default a = new _Default();
a = (_Default)Context.Handler;
this.Label2.Text = a.re();//获取用户输入的用户名并把它传给本页的Label2显示
this.TextBox1.Enabled = true;//把控件变为可编辑
Label5.Text = null;
}
}
为什么有的时候执行时没错,可重新生成解决方案或将VS关掉后再开时执行就出错。有的时候则更离谱,明明我已经删掉了一个控件了但执行时却又显示此控件,刚才执行时则在首次加载页面时不执行this.TextBox1.Enabled = false语句。
这究竟是什么原因呢?望各位大侠好心指导下,如果要改代码实现此功能的话要怎么改呢?
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
this.TextBox1.Enabled = false;//如是首次加载则把Textbox1置为不可编辑
}
else
if(!IsPostBack)
{
_Default a = new _Default();
a = (_Default)Context.Handler;
this.Label2.Text = a.re();//获取用户输入的用户名并把它传给本页的Label2显示
this.TextBox1.Enabled = true;//把控件变为可编辑
Label5.Text = null;
}
}
为什么有的时候执行时没错,可重新生成解决方案或将VS关掉后再开时执行就出错。有的时候则更离谱,明明我已经删掉了一个控件了但执行时却又显示此控件,刚才执行时则在首次加载页面时不执行this.TextBox1.Enabled = false语句。
这究竟是什么原因呢?望各位大侠好心指导下,如果要改代码实现此功能的话要怎么改呢?
if(!IsPostBack)
{
_Default a = new _Default();
a = (_Default)Context.Handler;
this.Label2.Text = a.re();
this.TextBox1.Enabled = true;
Label5.Text = null;
}
要重新编译再执行
wuyq11
那这段代码有错吗?
{
if (!Page.IsPostBack)
{
this.TextBox1.Enabled = false;//如是首次加载则把Textbox1置为不可编辑
}
else
{
_Default a = new _Default();
a = (_Default)Context.Handler;
this.Label2.Text = a.re();//获取用户输入的用户名并把它传给本页的Label2显示
this.TextBox1.Enabled = true;//把控件变为可编辑
Label5.Text = null;
}
}
lixinramaxel41658133大哥
有的时候就是比如把VS关了再开执行时就没有异常了,但是在重新生成解决方案后有出现异常