Detecting jQuery or C # ASP.Net page refresh

I was looking for a way to detect in my C # code if the page was refreshed (f5).

At first I don’t know if jQuery / JavaScript solution will be better than fully C # ASP.Net. So ... first question: what would you choose one by one?

And the third and most important part is if someone helped me with this. Some good textbook or article ... whatever. I tried some solutions there ... but maybe because of my lack of knowledge they did not work.

Thanks in advance.


update 1

I tried to make a Hightechrider solution because it is quite simple to implement. So I typed this code:

public bool IsRefresh { get; set; }

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);

    IsRefresh = false;
    if (Page.Request.AppRelativeCurrentExecutionFilePath == Profiles.User.LastPageUrl &&
        !Page.IsPostBack)
        IsRefresh = true;
}

PS: Profiles.User.LastPageUrl is a session variable that I created for other purposes, but it meets the needs of this. So this is not some kind of built-in property.

, PostBack Refresh . , "". , -! Page.IsPostBack. .

+3
3

, , , . , , .

, , :

, , , , . - . , , .

Javascript ( ), ASP.NET( ), , , , - , ., .

+1

, , VB.Net, #

    Private mRefreshState As Boolean
    Private mIsRefresh As Boolean

    Public ReadOnly Property IsRefreshFromPostBack() As Boolean
        Get
            Return mIsRefresh
        End Get
    End Property

    Protected Overrides Sub LoadViewState(ByVal savedState As Object)
        Dim allStates As Object() = DirectCast(savedState, Object())
        MyBase.LoadViewState(allStates(0))
        mRefreshState = Convert.ToBoolean(allStates(1))
        mIsRefresh = mRefreshState = Convert.ToBoolean(Session("__ISREFRESH"))
    End Sub

    Protected Overrides Function SaveViewState() As Object
        Session("__ISREFRESH") = mRefreshState
        Dim allStates(2) As Object
        allStates(0) = MyBase.SaveViewState()
        allStates(1) = Not mRefreshState
        Return allStates
    End Function

IsRefreshFromPostBack, , F5. ,

+1

, , , , . OnInit ( ). , PostBack.

0

Source: https://habr.com/ru/post/1736936/


All Articles