IsPostBack

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have a single page with a HyperLink server control on it. When the page
loads the first time, I have code that executes once. When you click on the
hyperlink server control to redirect, the page load executes again which is
fine, but the IsPostBack evaluates to false.

BUT I have code I want to execute ONLY the first time the page is called.
How do I work around this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
'Do something once
SomeMethodCall() 'But it executes BOTH times!
End If
End Sub

Thanks in advance!

Mark
 
Mark said:
I have a single page with a HyperLink server control on it. When the page
loads the first time, I have code that executes once. When you click on the
hyperlink server control to redirect, the page load executes again which is
fine, but the IsPostBack evaluates to false.

BUT I have code I want to execute ONLY the first time the page is called.
How do I work around this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
'Do something once
SomeMethodCall() 'But it executes BOTH times!
End If
End Sub

Thanks in advance!

Mark
I take from your description you're redirecting in the linkbutton click
event? A redirect involves doing a GET for the new page you specify
(IsPostBack is false). Are you redirecting to the same page?
 
Back
Top