Asp.net !IsPostBack返回始终为true

Asp.net !IsPostBack返回始终为true,asp.net,Asp.net,我正在尝试为我的gridview实现搜索操作。当我第一次加载我的页面时!iPostBack工作正常,但当我点击搜索按钮时,我的页面会再次加载!IsPostBack返回真值。因此,我无法执行搜索操作 这是我的密码 protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { ((Label)Master.FindControl("Label1")).Text = (string)Se

我正在尝试为我的gridview实现搜索操作。当我第一次加载我的页面时!iPostBack工作正常,但当我点击搜索按钮时,我的页面会再次加载!IsPostBack返回真值。因此,我无法执行搜索操作 这是我的密码

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        ((Label)Master.FindControl("Label1")).Text = (string)Session["sname"];

        fillData();
    }
}

public void fillData()
{
    if (con.State == ConnectionState.Open)
    {
        con.Close();
    }

    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT * FROM EBR_Supplier where DeleteFlag=" + 0 + " ORDER BY RowId ASC", con);
    SqlDataAdapter adap = new SqlDataAdapter(cmd);

    DataSet ds = new DataSet();

    adap.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();    
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    fillData();
}

protected void search_Click(object sender, EventArgs e)
{
    string id = txtid.Text;
    if (con.State == ConnectionState.Open)
    {
        con.Close();
    }

    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT * FROM EBR_Supplier where DeleteFlag=" + 0 + " and SupplierId='" + id + "' ORDER BY RowId ASC", con);
    SqlDataAdapter adap = new SqlDataAdapter(cmd);

    DataSet ds = new DataSet();
    adap.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

我自己找到了解决方案我的母版页上有一个表单控件。我删除了它对我的帮助。我感谢大家给我时间回答我的问题。

因为页面在提交页面时会发送一个post请求。如果您想在提交页面时实现某些功能,那么可以在其他部分编写代码。您知道,在sql查询中包含数据(如SupplierId='+id+'代码段)是非常糟糕的,对吗?你听说过sql注入吗?@VishalSuthar:当if条件为false时,它将执行else块。我的if条件总是返回truevalue@JoelCoehoorn:是的,我听说了sql注入。那么,您能帮助我如何改进我的查询吗?@ChhotumalIngole您能发布您的“.aspx”页面源代码吗?你可能把别的东西弄混了。