Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to check if page is refreshed in asp.net.

I want simple code to check page is refreshed or not
Posted

1 solution

Just tried a simple google search and found these links, check if these are useful
Using C#
C#
bool IsPageRefresh = false;

//this section of code checks if the page postback is due to genuine submit by user or by pressing "refresh"
if (!IsPostBack)     
{
    ViewState["ViewStateId"] = System.Guid.NewGuid().ToString();
    Session["SessionId"] = ViewState["ViewStateId"].ToString();
}
else
{
    if (ViewState["ViewStateId"].ToString() != Session["SessionId"].ToString())
    {
        IsPageRefresh = true;
    }

    Session["SessionId"] = System.Guid.NewGuid().ToString();
    ViewState["ViewStateId"] = Session["SessionId"].ToString();
}   

How to detect page refresh in .net[^]

Using Javascript:
Check if page reloaded or refresh in javascript[^]
or
How to check page is reloading or refreshing using jquery or javascript?[^]

Hope, it helps :)
 
Share this answer
 
v2
Comments
Member 14595909 22-Oct-19 14:10pm    
The first solution (bool IsPageRefresh = false;
) works great in Internet Explorer. Tried it in Chrome and somehow the viewstate is getting refreshed, so it never equals the session ID. Same code with both browsers.

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