When programming with Visual Studio in code. What means the Label in code?

A

Andreas Klemt

Hello,

for what is the label good when programming in visual studio like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Label1: If Page.IsPostBack Then
DoThis()
End If

Label2: DoThat()

End Sub

For what do I need or can use "Label1" and "Label2" ?

Thanks for any help an answers in advance!
Andreas
 
N

Natty Gur

Hi,

ASP.NET comes with build in mechanism of server events. Those events
start with a user action that took place on the client side. The user
action causes the page to be submitted back to the server. On the server
side the page events called, including certain control event. to
minimize the impact of recreating controls on post back MS create
another mechanism that saves controls state on the server into hidden
field that send to the client and send back to the server when server
side event required. ASP.NET use hidden field data to recreate controls
on the server (instead of recreating them for DB, for example).
IsPostBack is indication if the current call to the server side call is
result of Server side event or first time page call. You should use it
to prevent recreating of controls on postback.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
K

KatB

Andreas,

Example, you have a dropdownlist populated with names from a database
when page loads, and the user then selects an item.

When the user clicks on another control that causes postback (list,
button, etc.), you do not want your dropdownlist to repopulate from the
database, you want to keep the item the user selected.

So you set the dropdownlist control in the page load sub, using page is
(or is not) postback.


If Not IsPostBack Then

'populate dropdownlist here

End if

Please note that you don't need the "Else" part of the statement if you
are using ViewState...it will remember what the user selected from the
dropdownlist.

HTH,
Kat
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top