If Not Page.IsPostBack Then <-- HELP!!!

Discussion in 'ASP .Net' started by luna, Jan 27, 2004.

  1. luna

    luna Guest

    If Not Page.IsPostBack Then
    surname1.Text = "PASS"
    Else
    surname1.Text = "FAIL"
    End If

    Im new to aspx so apologies in advance

    Im using the above piece of code to try to ascertain what is happening with
    my webpage

    I created a webpage and put a button on it - simple enough

    when i click the button i want to retrieve some data from a SQL database and
    put it into different textboxes - seems simple enough

    the above 5 lines of code is my code behind my button
    Now surname1.text is never equal to PASS - why i dont know?

    if i dont include if not page.ispostback then
    the code seems to work - except that i cannot run any SQL commands on the
    DB

    any help again is greatly appreciated

    Mark.
    luna, Jan 27, 2004
    #1
    1. Advertising

  2. luna

    Curt_C [MVP] Guest

    if this is in the button_click event then it's ALWAYS a post back, you are
    saying "IF NOT", but that will always indicate "false"

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "luna" <> wrote in message
    news:2BvRb.444$...
    > If Not Page.IsPostBack Then
    > surname1.Text = "PASS"
    > Else
    > surname1.Text = "FAIL"
    > End If
    >
    > Im new to aspx so apologies in advance
    >
    > Im using the above piece of code to try to ascertain what is happening

    with
    > my webpage
    >
    > I created a webpage and put a button on it - simple enough
    >
    > when i click the button i want to retrieve some data from a SQL database

    and
    > put it into different textboxes - seems simple enough
    >
    > the above 5 lines of code is my code behind my button
    > Now surname1.text is never equal to PASS - why i dont know?
    >
    > if i dont include if not page.ispostback then
    > the code seems to work - except that i cannot run any SQL commands on

    the
    > DB
    >
    > any help again is greatly appreciated
    >
    > Mark.
    >
    >
    Curt_C [MVP], Jan 27, 2004
    #2
    1. Advertising

  3. luna

    Scott Allen Guest

    A button press causes your form to post back to the server, thus
    IsPostBack will always be true when an event happens.

    Is this code in Page_Load or some other event handler? If you show us
    the code you are trying to use to execute SQL commands I'm sure
    someone will be able to help you.

    --
    Scott
    http://www.OdeToCode.com

    On Tue, 27 Jan 2004 15:38:12 -0000, "luna" <> wrote:

    >If Not Page.IsPostBack Then
    > surname1.Text = "PASS"
    >Else
    > surname1.Text = "FAIL"
    >End If
    >
    >Im new to aspx so apologies in advance
    >
    >Im using the above piece of code to try to ascertain what is happening with
    >my webpage
    >
    >I created a webpage and put a button on it - simple enough
    >
    >when i click the button i want to retrieve some data from a SQL database and
    >put it into different textboxes - seems simple enough
    >
    >the above 5 lines of code is my code behind my button
    >Now surname1.text is never equal to PASS - why i dont know?
    >
    >if i dont include if not page.ispostback then
    >the code seems to work - except that i cannot run any SQL commands on the
    >DB
    >
    >any help again is greatly appreciated
    >
    >Mark.
    >
    Scott Allen, Jan 27, 2004
    #3
  4. Whenever you enter the page, you are in the NOT ISPOSTBACK, so since the
    first time that you click the button, you´ll be in a POSTBACK...

    The condition If not IsPostBack is used in the Page_Load, usually to fill
    controls and other actions that should only be performed once...

    Cristhian,
    Mx

    "luna" <> escribió en el mensaje
    news:2BvRb.444$...
    > If Not Page.IsPostBack Then
    > surname1.Text = "PASS"
    > Else
    > surname1.Text = "FAIL"
    > End If
    >
    > Im new to aspx so apologies in advance
    >
    > Im using the above piece of code to try to ascertain what is happening

    with
    > my webpage
    >
    > I created a webpage and put a button on it - simple enough
    >
    > when i click the button i want to retrieve some data from a SQL database

    and
    > put it into different textboxes - seems simple enough
    >
    > the above 5 lines of code is my code behind my button
    > Now surname1.text is never equal to PASS - why i dont know?
    >
    > if i dont include if not page.ispostback then
    > the code seems to work - except that i cannot run any SQL commands on

    the
    > DB
    >
    > any help again is greatly appreciated
    >
    > Mark.
    >
    >
    Cristhian Job, Jan 27, 2004
    #4
  5. luna

    luna Guest

    hi,

    thanks for the help - not sure exactly what i did but its working now - just
    tried lots of things till it worked!
    i just got rid of the ispostback statement and it was fine (i originally got
    a asp code example - had to make a
    few changes for aspx with code behind)

    thanks

    mark



    "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    news:...
    > A button press causes your form to post back to the server, thus
    > IsPostBack will always be true when an event happens.
    >
    > Is this code in Page_Load or some other event handler? If you show us
    > the code you are trying to use to execute SQL commands I'm sure
    > someone will be able to help you.
    >
    > --
    > Scott
    > http://www.OdeToCode.com
    >
    > On Tue, 27 Jan 2004 15:38:12 -0000, "luna" <> wrote:
    >
    > >If Not Page.IsPostBack Then
    > > surname1.Text = "PASS"
    > >Else
    > > surname1.Text = "FAIL"
    > >End If
    > >
    > >Im new to aspx so apologies in advance
    > >
    > >Im using the above piece of code to try to ascertain what is happening

    with
    > >my webpage
    > >
    > >I created a webpage and put a button on it - simple enough
    > >
    > >when i click the button i want to retrieve some data from a SQL database

    and
    > >put it into different textboxes - seems simple enough
    > >
    > >the above 5 lines of code is my code behind my button
    > >Now surname1.text is never equal to PASS - why i dont know?
    > >
    > >if i dont include if not page.ispostback then
    > >the code seems to work - except that i cannot run any SQL commands on

    the
    > >DB
    > >
    > >any help again is greatly appreciated
    > >
    > >Mark.
    > >

    >
    luna, Jan 27, 2004
    #5
    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. =?Utf-8?B?TWlrZQ==?=

    greater then / less then

    =?Utf-8?B?TWlrZQ==?=, Nov 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,581
    Kevin Spencer
    Nov 4, 2004
  2. Joey
    Replies:
    2
    Views:
    3,939
  3. JosephByrns

    Slow, then quick then slow

    JosephByrns, Jul 10, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,487
    codezilla94
    Nov 13, 2007
  4. Replies:
    0
    Views:
    270
  5. Replies:
    15
    Views:
    216
Loading...

Share This Page