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

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.
 
C

Curt_C [MVP]

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"
 
S

Scott Allen

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.
 
C

Cristhian Job

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
 
L

luna

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
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top