Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview in the asp.net page. When I insert data into the gridview the whole page will reload. How to avoid this? Here is my code
C#
protected void AddNewCustomer(object sender, EventArgs e)
   {

       Control control = null;
       if (GridView1.FooterRow != null)
       {
           control = GridView1.FooterRow;
       }
       else
       {
           control = GridView1.Controls[0].Controls[0];
       }
       string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
       string Code = (control.FindControl("txtcode") as TextBox).Text;
       string details = (control.FindControl("txtdetails") as TextBox).Text;
       using (SqlConnection con = new SqlConnection(""))
       {
           using (SqlCommand cmd = new SqlCommand())
           {
               cmd.Connection = con;
               cmd.CommandType = CommandType.Text;
               cmd.CommandText = "INSERT INTO [Qtattemp] VALUES(@Code,@details,@SlNo)";
               cmd.Parameters.AddWithValue("@SlNo", SlNo);
               cmd.Parameters.AddWithValue("@Code", Code);
               cmd.Parameters.AddWithValue("@details", details);
               con.Open();
               cmd.ExecuteNonQuery();
               con.Close();
           }
       }
       Response.Redirect(Request.Url.AbsoluteUri);
   }
Posted

C#
Response.Redirect(Request.Url.AbsoluteUri);// This line reloading the whole page.

Tip:
If you want to see the changes after the operation, create one method and write the code for assigning the data to gridview.
And at the end of your operation, call this method.

-KR
 
Share this answer
 
Comments
Sivajihero Hero 3-Oct-15 5:40am    
Sir I have removed the code, still the same pblm.The page refresh aft I click on the add button in gridview.
Krunal Rohit 3-Oct-15 5:49am    
I don't think so. With the given this was the only issue.
If it is still reloading then there has to be something somewhere else.

-KR
You are redirecting to some page at last. If that is not required, then remove.
 
Share this answer
 
pls anybody have any idea regarding this.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900