Page.IsPostBack Property

N

nly

Page.IsPostBack Property

"The Page_Load subroutine runs EVERY time the page is loaded. If you want to
execute the code in the Page_Load subroutine only the FIRST time the page is
loaded, you can use the Page.IsPostBack property. If the Page.IsPostBack
property is false, the page is loaded for the first time, if it is true, the
page is posted back to the server (i.e. from a button click on a form)..."

Let's say we have this in a "body" of an aspx page:

<form runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
<asp:button text="Submit" onclick="submit" runat="server" />
</form>

What does it mean by "the page is posted back to the server"? What's exactly
posted back here in the above example?

Thanks in advance!
 
T

Tasos Vogiatzoglou

First of all the onclick attribute in an asp:button components must a
method in your code-behind.

Postback is generated every time you raise an event from a server-side
control. Thus when you click the "asp:button" text the page will be
posted-back.


Hope this helped ...
 
N

nly

Tasos Vogiatzoglou said:
First of all the onclick attribute in an asp:button components must a
method in your code-behind.

Postback is generated every time you raise an event from a server-side
control. Thus when you click the "asp:button" text the page will be
posted-back.
What does it mean by "the page ...(is)...posted-back"?
 
C

Cor Ligthert [MVP]

nly,

Have a look at your HTML forms part of your page.

That information is posted back if you click on a control that has
autosentback set to true. Autosentback is default by some controls as the
button, however default false by some as by instance the listbox.

If it is "sentback", than everytime the data can be processed. The
IsPostBack is most often placed in the load event of the page in the code
behind.

By instance

if (IsPostBack) {
//Get Information From Database
}
else{
//Get information from Session item
}

I hope this helps,

Cor
 
C

Cor Ligthert [MVP]

Oeps,

Typed it here in the message

if (IsPostBack) {
//Get Information From Session
}
else{
//Get information from DataBase
}

I use mostly the ! situation.

:)

Cor
 

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

Top