Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
When I refresh or reload the page with the imagebutton, the script for this button runs, how can I stop this happen. I have tried this option, but this will not always invoke IsPostBack or IsRefresh right.

VB
Protected Sub imgBtnAktivate_Click (sender As Object, e As System.Web.UI.ImageClickEventArgs ) Handles imgBtnAktivate.Click
        If IsPostBack Then
            If CBool(HttpContext.Current.Items("IsRefresh")) Then
                'Response.Write("refreshed")
                Label1.Text = "Refreshed"

                Exit Sub
            Else
                Label1.Text = "Postback"
    Generate_Numbers ()

    Dim RemoteURL As String = " http://www.domene.com/recipient.aspx "
    Dim encoding As ASCIIEncoding = New ASCIIEncoding
    Dim data As String = String.Format ( " DomName = { 0 } & DomeneSNr = {1 } & SerNr = {2 }", sDomName , sDomeneSNr , sSerNr )
    Dim bytes ( ) As Byte = encoding.GetBytes (data )
    Dim HttpRequest As HttpWebRequest = ctype ( WebRequest.Create ( RemoteURL ) , HttpWebRequest )

    httpRequest.Method = " POST "
    httpRequest.ContentType = " application / x -www - form - urlencoded "
    httpRequest.ContentLength = bytes.Length ( )

    Dim stream As IO.Stream = httpRequest.GetRequestStream
    stream.Write ( bytes , 0, bytes.Length )
    stream.Close ( )
           End If
        Else
            Exit Sub
        End If
end Sub
Posted
Updated 12-Mar-14 5:00am
v4
Comments
Sergey Alexandrovich Kryukov 11-Mar-14 19:17pm    
"Backcode"? What is that?
—SA

You can check your answer here:

Avoid button click event on page refresh[^]

Similar questions can be found here also:

http://www.c-sharpcorner.com/Forums/[^]
 
Share this answer
 
Hi,

Please try with javascript to refresh the page. you have another event on your image button onclientclick or direct you can put onclick event and use the below javascript code.





function pagerefresh()
{
window.reload();

}



your button event like onclick="pagerefresh()"

Thanks,
 
Share this answer
 
This did the job!
VB
Private _refreshState As Boolean
Private _isRefresh As Boolean

Protected Overrides Sub LoadViewState(ByVal savedState As Object)

    Dim AllStates As Object() = savedState
    MyBase.LoadViewState(AllStates(0))
    _refreshState = Boolean.Parse(AllStates(1))
    _isRefresh = _refreshState = Session("__ISREFRESH")

End Sub

Protected Overrides Function SaveViewState() As Object

    Session("__ISREFRESH") = _refreshState
    Dim AllStates() As Object = New Object(2) {}
    AllStates(0) = MyBase.SaveViewState
    AllStates(1) = Not (_refreshState)
    Return AllStates

End Function
 
Share this answer
 

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