How to solve this problem of back button on browser.

I have the following code to save the data.
front end as
<table>
<tr>   <td class="td_style  report_color">
            <div align="center">
                <asp:Button ID="btnsave" runat="server" Text="Save Entry" onclick="btnsave_Click"
                     />
            </div>
            </td>
</tr>
<table>
in code behind
protected void btnsave_Click(object sender, EventArgs e)
    {
        try
        {
            btnsave.Enabled = false;
            if (chkconfirm.Checked == true)
            {
                cmd = new SqlCommand("savem1form", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = con;
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                cmd.Parameters.AddWithValue("@source", txtsource.Text.Trim());
                cmd.Parameters.AddWithValue("@state", txtstate.Text.Trim());
                cmd.Parameters.AddWithValue("@district", ddldistricts.SelectedItem.Text.Trim());
                cmd.Parameters.AddWithValue("@phc_chc_name", txtphc_chc_name.Text.Trim());
                cmd.Parameters.AddWithValue("@sub_centre", txtsub_centre.Text.Trim());
                cmd.Parameters.AddWithValue("@village", txtvillage.Text.Trim());
                cmd.Parameters.AddWithValue("@chv_name", txtchvname.Text.Trim());
                cmd.Parameters.AddWithValue("@uin", Convert.ToInt32(ddluin.SelectedItem.Text.Trim()));
                cmd.Parameters.AddWithValue("@sno", txtsno.Value);
                cmd.Parameters.AddWithValue("@patient", txtpatient.Text.Trim());
                cmd.Parameters.AddWithValue("@hof", txthof.Text.Trim());
                cmd.ExecuteNonQuery();
                Response.Write("<script>alert('Record saved successfully')</script>");
                con.Close();
                callreset();

            }
        }
        catch (Exception ee)
        {
            Response.Write(ee.ToString());
        }
    }
-----------------------------------------------------------------------
When the user clicks on btnsave, the data gets saved, the message comes as Record Saved Successfully, then the user is directed on same page
with save button ge tting disabled and new button getting activated, then the user add the data and save gets activated and the process is repeated.

The problem is when the user clicks on is returned on same page, if presses back button all the values are there and he can press save button as many time.
I want to make this work like as the that when the user clicks on back button of browser the page should be lost.Is it possible.

Like when we pay online payment the old pages gets lost.

I am using asp.net using C#
searchsanjaysharmaAsked:
Who is Participating?
 
abhinayp86Connect With a Mentor Commented:
One way is to refresh the page completely whenever user clicks on the back button (basically on every load)

public class ProductBrowser : Page
{
    protected override void OnInit(EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        Response.Cache.SetExpires(DateTime.MinValue);

        base.OnInit(e);
    }
}

Open in new window

http://stackoverflow.com/questions/1189285/back-button-refresh-page
0
 
searchsanjaysharmaAuthor Commented:
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.