Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine difference between an autopostback or a page refresh 2

Status
Not open for further replies.

blar9

Programmer
Mar 12, 2007
39
US
Is there a way to determine if a user clicked refresh on the page or clicked a control that causes a postback?

Thanks
 
You could also look in the EVENTTARGET parameter. I've grabbed an example that we used in an old project where you just pass the page to the function and it returns the control that caused the postback. Presumably, if the control is Nothing when it is returned, then it wasn't a postback. I've not tested this but if you wanted to have a play around with it, here's what was used:
Code:
    Public Function GetPostBackControl(ByVal page As System.Web.UI.Page) As System.Web.UI.Control
        ' Find which control caused the postback
        Dim control As Control = Nothing
        Dim ctrlname As String = page.Request.Params("__EVENTTARGET")
        If Not (ctrlname Is Nothing) AndAlso Not (ctrlname = String.Empty) Then
            control = page.FindControl(ctrlname)
        Else
            Dim ctrlStr As String = String.Empty
            Dim c As Control = Nothing
            For Each ctl As String In page.Request.Form
                If ctl.EndsWith(".x") OrElse ctl.EndsWith(".y") Then
                    ctrlStr = ctl.Substring(0, ctl.Length - 2)
                    c = page.FindControl(ctrlStr)
                Else
                    c = page.FindControl(ctl)
                End If
                If TypeOf c Is System.Web.UI.WebControls.Button OrElse TypeOf c Is System.Web.UI.WebControls.ImageButton Then
                    control = c
                    ' break
                End If
            Next
        End If
        Return control
    End Function


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top