Sivajihero Hero
Sivajihero Hero

Reputation: 67

How to avoid page reload after inserting data into the gridview

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

 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);
}

Upvotes: 0

Views: 51

Answers (1)

user3497034
user3497034

Reputation:

I think that the issue cause with Response.Redirect(Request.Url.AbsoluteUri); so,You need to specify it after function completion.It might be solve your problem.

Upvotes: 1

Related Questions