How to avoid execution of page_load event before click event of a

Discussion in 'ASP .Net' started by Guest, Apr 3, 2006.

  1. Guest

    Guest Guest

    I have a page where I initialize a textbox.text value in the page_load event
    .. I have also a button where I want to do something with the value of the
    textbox.text . The user can change manually the value of the textbox. I have
    noticed that the textbox.Text property has always the initial value inside
    the the click event of the buttom because the page_load event is executed
    always before the click event. Any way to avoid this?

    Thanks
     
    Guest, Apr 3, 2006
    #1
    1. Advertisements

  2. Guest

    sirfunusa Guest

    That is incorrect. The click event (on the server) happens first,
    before the page is rendered back to the client. Post the minimum code
    necessary here to demonstrate your problem.
     
    sirfunusa, Apr 3, 2006
    #2
    1. Advertisements

  3. Guest

    sirfunusa Guest

    Oh, perhaps you mean the "server" page load happens first, which is
    true. Then use

    If Not Page.IsPostBack...
    .....

    End if
     
    sirfunusa, Apr 3, 2006
    #3
  4. Guest

    rachana Guest

    use IsPostback.

    if(!IsPostBack)
    {
    // code to initialize textbox
    }

    Now when the button is clicked, page is reloaded but as it is being
    posted back the code in if block won't execute, so textbox.text won't
    be reinitialized.
     
    rachana, Apr 3, 2006
    #4
  5. Guest

    Guest Guest

    Thank you, that's what I need
     
    Guest, Apr 4, 2006
    #5
  6. Guest

    Guest Guest

    Thank you, that's what I need
     
    Guest, Apr 4, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.