C# .NET - prevent firing textchanged event on every post back

Asked By muthuraman alexander on 18-Nov-11 02:02 AM
hi all
i have a grid view for sales item
and
i have a textbox inside the grid view  for entering the quandity
based on the quantity the total field in the  grid view got affected..so i have  a text changed event ..
but the text change event got fired every time of postback or grid bind

how can i avoid this
i want to prevent the textchanged event to be called every time in the grid view bind or during the post back

please advice me

thanks in advance
MUTHU


Chintan Vaghela replied to muthuraman alexander on 18-Nov-11 02:16 AM
Hello,

u need to write !IsPostback in page load event as follows to avoid postback


protected void Page_Load(object sender, EventArgs e)

      {

        if (!IsPostBack)

        {

          BindGrid();

        }

      }


dipa ahuja replied to muthuraman alexander on 18-Nov-11 02:31 AM
Bind the Grid inside the page_Load's IsPostBack condition

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    bindGrid();
  }
}
void bindGrid()
{
  SqlDataAdapter da = new SqlDataAdapter("select * from TableName", "Connection String");
  DataTable dt = new DataTable();   
  da.Fill(dt);
  GridView1.DataSource = dt;
  GridView1.DataBind();
}
 
And during postBack is should not occur, because textchange only fires when the textbox text is being changed.

So you can try to put the gridview inside the updatePanel, it may solve this