Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There are a forum on my asp.net website where user can save his personal details. my problem is that when user details submitted successfully in database and he / she again refresh URL (f5), event again aeries and request go to server, double entry saved in database. I do not want to redirect same page or another page, how i can handle it.
Posted
Comments
Nandakishore G N 2-Jul-13 1:19am    
are you inserting data during page load? paste the code what have you done?

C#
private bool _refreshState;
    private bool _isRefresh;

    protected override void LoadViewState(object savedState)
    {
        object[] AllStates = (object[])savedState;
        base.LoadViewState(AllStates[0]);
        _refreshState = bool.Parse(AllStates[1].ToString());
        _isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString());
    }


    protected override object SaveViewState()
    {
        Session["__ISREFRESH"] = _refreshState;
        object[] AllStates = new object[2];
        AllStates[0] = base.SaveViewState();
        AllStates[1] = !(_refreshState);
        return AllStates;
    }

//button click event
    protected void btn_Click(object sender, EventArgs e)
    {
        if (!_isRefresh)
            {
            //Working code
            Response.Write(DateTime.Now.Millisecond.ToString());
            }
    }
 
Share this answer
 
v2
Comments
Moshe Ohrinovitch 11-Sep-13 5:13am    
This is the perfect solution, the first that works!
Could you please add some comments to the code and elaborate?
Thanks!
Clear values of all control after submit values.
And you should use any pop message like "Insert successfully" or you can redirect on same page with use of Response.Redirect("YourPage.aspx");
 
Share this answer
 
Comments
ashok luhach 2-Jul-13 0:57am    
There are no other solution by which i can stop raised event
jaideepsinh 2-Jul-13 2:15am    
This is the simple way to solve your problem and if you want to use other way then think may be it's use of update panel.
jaideepsinh 2-Jul-13 6:05am    
Please mark as answer if solve your problem.
 
Share this answer
 
v2

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