IsPostBack

Discussion in 'ASP .Net' started by Mark, Feb 10, 2004.

  1. Mark

    Mark Guest

    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, Feb 10, 2004
    #1
    1. Advertising

  2. Mark wrote:
    > 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?

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Feb 10, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Baulch
    Replies:
    1
    Views:
    967
    Nathan Baulch
    Jun 26, 2003
  2. suzy
    Replies:
    11
    Views:
    750
    Rajeev Soni
    Aug 6, 2003
  3. Matthew
    Replies:
    1
    Views:
    1,476
    Matthew
    Nov 12, 2003
  4. Boris Zakharin

    IsPostBack returns false

    Boris Zakharin, Nov 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    643
    Boris Zakharin
    Nov 19, 2003
  5. Joey
    Replies:
    2
    Views:
    3,940
Loading...

Share This Page