一个按钮响应的问题

sam_jiang 2010-01-17 08:09:35
一个按钮
<asp:Button ID="Btnquery" runat="server" Text="查询" OnClick="Btnquery_Click" />

它提交的是,多条件查询(Textbox),但是点击查询按钮后,总是无法执行Btnquery_Click(),设置断点也到不了那里,而是直接执行
Page_Load就停止了,导致在后台.cs中就无法得到Textbox的值,不知道是什么原因。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//BindGridView(); //如果放在这里就能够执行,但是得不到点击按钮前填入的值。
}

}

private void BindGridView()
{
SQLHelper sql = new SQLHelper();
DataSet dt = new DataSet();
string strSql = "select * from GeomDf where 1 = 1";

if (this.dateinput1.Text != "")
strSql += " and rundate1 = '" + this.dateinput1.Text + "'";
if (this.dateinput2.Text != "")
strSql += " and rundate2 = '" + this.dateinput2.Text + "'";


sql.RunSQL(strSql, ref dt);
GridView1.DataSource = dt.Tables[0];
GridView1.DataBind();

}


protected void Btnquery_Click(object sender, EventArgs e)
{
BindGridView();
}

代码如上,不知道为何就不能执行,要是如注释写的那样放在page_load中就能执行,但是放在page_load中就得不到点击按钮前输入的值。不知道问题出在什么地方。

谢谢了~
应该怎么改才能实现这个多条件查询呢
...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sam_jiang 2010-01-17
  • 打赏
  • 举报
回复
这个是aspx里面的textbox

<asp:textbox id="dateinput1" runat="server" Columns="15" MaxLength="50" onfocus="calendar()"></asp:textbox>
<asp:textbox id="dateinput2" runat="server" Columns="15" MaxLength="50" onfocus="calendar()"></asp:textbox>

不知道有哪里没有设置好?
sam_jiang 2010-01-17
  • 打赏
  • 举报
回复
aspx页面的设置
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation = "true" CodeFile="test.aspx.cs" Theme="Staff" Inherits="test" %>
sam_jiang 2010-01-17
  • 打赏
  • 举报
回复
这样跟踪的结果就是,在点击按钮之前,输入textbox的值没有传进来,=null。
wuyq11 2010-01-17
  • 打赏
  • 举报
回复
if (!IsPostBack)
{
BindGridView();
}

string strSql = "select * from GeomDf where 1 = 1";
strSql +=string.IsNullOrEmpty(this.dateinput1.Text)?"":" and rundate1 = '" + this.dateinput1.Text + "'";
strSql +=string.IsNullOrEmpty(this.dateinput2.Text)?"":" and rundate2 = '" + this.dateinput2.Text + "'";
单步跟踪看看

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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