新手低级问题,麻烦指条明路!

trial 2006-11-17 11:29:06
--------------Default-----------------
protected void Page_Load(object sender, EventArgs e)
{
if ((TextBox1.Text == "") || (TextBox2.Text==""))
{
SqlStr = "Select * from News_ds order by sendtime desc";
}
else
{
***
}
}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
First=Convert.ToDateTime(TextBox1.Text);
Last=Convert.ToDateTime(TextBox2.Text);
}
catch(Exception ex)
{
Response.Write(ex);
}
finally
{

}
}

希望用Button1_Click()执行验证。
但是运行情况下来就是先执行
if ((TextBox1.Text == "") || (TextBox2.Text==""))
{
****
}
else
{
****
}
然后再执行Button_Click(),导致我的验证无法正常执行,请问该如何修改!
...全文
108 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ll_net 2006-11-17
  • 打赏
  • 举报
回复
楼上正解
BearRui 2006-11-17
  • 打赏
  • 举报
回复
if (!IsPostBack)
yao991118 2006-11-17
  • 打赏
  • 举报
回复
楼主啊,当然是先执行Page_Load事件了
如果你要先执行Button1_Click()事件,就在Page_Load事件里强制调用Button1_Click()事件嘛,如:
protected void Page_Load(object sender, EventArgs e)
{
this.Button1_Click(null, null)
if ((TextBox1.Text == "") || (TextBox2.Text==""))
{
SqlStr = "Select * from News_ds order by sendtime desc";
}
else
{
***
}
}
BearRui 2006-11-17
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostback)
{
if ((TextBox1.Text == "") || (TextBox2.Text==""))
{
SqlStr = "Select * from News_ds order by sendtime desc";
}
else
{
***
}
}
}
dengenming 2006-11-17
  • 打赏
  • 举报
回复
出什么错啊...问问题要说清楚
trial 2006-11-17
  • 打赏
  • 举报
回复
判断了,msg是该页中的一个全局变量;
可是MSG变量单击以后变成"AAA"了,但是翻页以后 MSG变量的“AAA”为什么会丢失?
chinalinx 2006-11-17
  • 打赏
  • 举报
回复
先判断是否为提交表单页

呵呵:)
trial 2006-11-17
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
Response.write(msg);
}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
msg="AAA"
}
catch(Exception ex)
{
Response.Write(ex);
}
finally
{

}
}

可是我单击了按钮以后 MSG变量依然是空,这是为什么呢?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧