IsPostBack

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
 
C

Craig Deelsnyder

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top