Click here to Skip to main content
12,945,945 members (60,212 online)
Rate this:
Please Sign up or sign in to vote.
See more:
protected void Button3_Click(object sender, EventArgs e)
   bool isAnythingChecked = false;
   foreach (GridViewRow row in GridView1.Rows)
      CheckBox chk = (CheckBox)row.FindControl("chk1");
      string empname = row.Cells[1].Text;
      string leaveid = row.Cells[2].Text;
      if (chk != null && chk.Checked)
         isAnythingChecked = true;
              //Create sql connection and command
              string strConnect;
              strConnect = "Data Source=BALA;Initial Catalog=employees;Persist Security Info=True;User ID=sa;Password=mips123";
              SqlConnection Connection = new SqlConnection(strConnect);
              string strUpdate = "Update Leave set status = 'Approved' WHERE (LeaveID =" + leaveid + ") AND (EmpID = (Select EmpID from Emp where (Empname='" + empname + "')))";
              SqlCommand command = new SqlCommand(strUpdate, Connection);
          catch (Exception exc)
   if (!isAnythingChecked)
      Label2.Text = "Please select atlease one record";
       how to avoid page postback on button click ,please help me friends
Posted 30-Jan-13 20:00pm
Updated 31-Jan-13 2:03am
AdityaPratapSingh 31-Jan-13 2:09am
what do u want ? write your question here in meaningful sense.
_Amy 31-Jan-13 2:11am
Your question is completely Incomplete/Unclear. Please improve your question so that we can understand the error.
sjelen 31-Jan-13 7:09am
What else part are you talking about - you didn't show that code? Page is supposed to postback on button click, that's how ASP webforms work.
Explain what you are trying to achieve.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well, what is the question.
Page will definitely post back on button click (or any such event or server side control). You need to handle your code in Page_Load using isPostBack

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
//First time page load
// subsequent page load

Hope that helps
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hello mbsaravanan575,

Put your Content inside Update Panel

It May Help You.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100