This is a migrated thread and some comments may be shown as answers.

refresh fires insertcommand

3 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Borneman
Top achievements
Rank 1
David Borneman asked on 02 Feb 2008, 06:01 AM
Why would a page refresh fire the grid's insertcommand? If you add a new row with auto-insert enabled and then right-click and refresh the screen it fires the insertcommand again. How can I stop this behavior? 

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 04 Feb 2008, 07:52 AM
Hi David,

If you are using regular post-backs the page refresh will attempt to repost last post to the server - this will not happen if you use ajax.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Simone
Top achievements
Rank 1
answered on 01 Jul 2011, 09:32 PM
Same problem here. Can you be more specific as how to enable Ajax so it doesn't insert every time you refresh?
Thanks.
0
komathi priya
Top achievements
Rank 1
answered on 02 Jul 2011, 12:14 PM
Hi 

Add the below methods in your page 

 #region Browser Refersh
    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());
        if (Session["ISREFRESH"] != "" && Session["ISREFRESH"] != null)
            isRefresh = (refreshState == (bool)Session["ISREFRESH"]);
    }

    protected override object SaveViewState()
    {
        Session["ISREFRESH"] = refreshState;
        object[] AllStates = new object[3];
        AllStates[0] = base.SaveViewState();
        AllStates[1] = !(refreshState);
        return AllStates;
    }

    #endregion 



and in your insert command check the isRefresh value, if it's false then perform the insert action, 
isRefresh will be true if the page reloaded by using the refresh button. 
 

protected void grd_InsertCommand(object source, GridCommandEventArgs e)
    {
         if (isRefresh == false)
            {
//Your Coding....
}
}






Tags
Grid
Asked by
David Borneman
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Simone
Top achievements
Rank 1
komathi priya
Top achievements
Rank 1
Share this question
or