F5 Refersh/Button Click [modified]
-
When an user clicks on a button click event and after the event got executed, if he hits on F5 key or Refresh button, the same button click event executes once again. How i can avoid this in ASP.Net 2.0.? Moreover i clear all the controls, so that it should fire javascript for mandatory fields. Instread of that it is rerading the values from cache..... I tried Button, HTML Submit and as well as ImageButton....But same behaviour.... Source Code: public partial class RepeaterFormControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { GetDataFromDatabase(); if (!(IsPostBack)) { Button1.Attributes.Add("onclick", "return ValidateInput();"); } } private void GetDataFromDatabase() { SQLDataAccessHelper daHelper = new SQLDataAccessHelper(); this.Repeater1.DataSource=daHelper.ExecuteReader(CommandType.StoredProcedure, "GetFormViewData"); this.Repeater1.DataBind(); } protected void clearControls() { ((TextBox)(FormView1.FindControl("TxtFName"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtLName"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtEmail"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtDob"))).Text = ""; } protected void btnSave_Click(object sender, ImageClickEventArgs e) { String sFname = ((TextBox)(FormView1.FindControl("TxtFName"))).Text.ToString(); String sLname = ((TextBox)(FormView1.FindControl("TxtLName"))).Text.ToString(); String sEmail = ((TextBox)(FormView1.FindControl("TxtEmail"))).Text.ToString(); string sDOB = ((TextBox)(FormView1.FindControl("TxtDob"))).Text.ToString(); String sCountry = ((DropDownList)(FormView1.FindControl("CmbCountry"))).SelectedItem.Text.ToString(); SQLDataAccessHelper daHelper = new SQLDataAccessHelper(); IDataParameter[] objparam; objparam = daHelper.GetSpParameterSet("AddFormViewData"); objparam[0].Value = sFname; objparam[1].Value = sLname; objparam[2].Value = sEmail; objparam[3].Value = sDOB; objparam[4].Value = sCountry; daHelper.ExecuteNonQuery("AddFormViewData", objparam); GetDataFromDatabase(); clearControls(); sFname = ""; sLname = ""; sEmail = ""; sDOB = ""; } } And ASPX code....
-
When an user clicks on a button click event and after the event got executed, if he hits on F5 key or Refresh button, the same button click event executes once again. How i can avoid this in ASP.Net 2.0.? Moreover i clear all the controls, so that it should fire javascript for mandatory fields. Instread of that it is rerading the values from cache..... I tried Button, HTML Submit and as well as ImageButton....But same behaviour.... Source Code: public partial class RepeaterFormControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { GetDataFromDatabase(); if (!(IsPostBack)) { Button1.Attributes.Add("onclick", "return ValidateInput();"); } } private void GetDataFromDatabase() { SQLDataAccessHelper daHelper = new SQLDataAccessHelper(); this.Repeater1.DataSource=daHelper.ExecuteReader(CommandType.StoredProcedure, "GetFormViewData"); this.Repeater1.DataBind(); } protected void clearControls() { ((TextBox)(FormView1.FindControl("TxtFName"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtLName"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtEmail"))).Text = ""; ((TextBox)(FormView1.FindControl("TxtDob"))).Text = ""; } protected void btnSave_Click(object sender, ImageClickEventArgs e) { String sFname = ((TextBox)(FormView1.FindControl("TxtFName"))).Text.ToString(); String sLname = ((TextBox)(FormView1.FindControl("TxtLName"))).Text.ToString(); String sEmail = ((TextBox)(FormView1.FindControl("TxtEmail"))).Text.ToString(); string sDOB = ((TextBox)(FormView1.FindControl("TxtDob"))).Text.ToString(); String sCountry = ((DropDownList)(FormView1.FindControl("CmbCountry"))).SelectedItem.Text.ToString(); SQLDataAccessHelper daHelper = new SQLDataAccessHelper(); IDataParameter[] objparam; objparam = daHelper.GetSpParameterSet("AddFormViewData"); objparam[0].Value = sFname; objparam[1].Value = sLname; objparam[2].Value = sEmail; objparam[3].Value = sDOB; objparam[4].Value = sCountry; daHelper.ExecuteNonQuery("AddFormViewData", objparam); GetDataFromDatabase(); clearControls(); sFname = ""; sLname = ""; sEmail = ""; sDOB = ""; } } And ASPX code....
Here is the reply http://aspalliance.com/articleViewer.aspx?aId=687&pId=-1 Thanks!!