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

Discussion in 'ASP .Net' started by Andreas Klemt, Jan 14, 2004.

  1. 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
     
    Andreas Klemt, Jan 14, 2004
    #1
    1. Advertisements

  2. Andreas Klemt

    Natty Gur Guest

    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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, Jan 14, 2004
    #2
    1. Advertisements

  3. Andreas Klemt

    KatB Guest

    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    KatB, Jan 14, 2004
    #3
    1. Advertisements

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. John Timbers
    Replies:
    32
    Views:
    1,743
    Alvin Bruney
    Nov 8, 2003
  2. wh
    Replies:
    2
    Views:
    857
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  3. Rob Meade
    Replies:
    2
    Views:
    521
    Rob Meade
    May 22, 2004
  4. M P
    Replies:
    6
    Views:
    757
    Joe Fallon
    Aug 7, 2004
  5. Thirumalai
    Replies:
    0
    Views:
    1,000
    Thirumalai
    May 22, 2006
  6. rockdale
    Replies:
    1
    Views:
    925
    Juan T. Llibre
    Aug 23, 2006
  7. xman
    Replies:
    1
    Views:
    888
    Victor Bazarov
    Aug 17, 2005
  8. Knut Krueger
    Replies:
    8
    Views:
    612
    Knut Krueger
    Aug 20, 2013
Loading...