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

  • Thread starter Thread starter luna
  • Start date Start date
L

luna

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.
 
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"
 
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.
 
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
 
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
 
Back
Top