OnLoad (dropdownlist) is executed before OnClick (Button)

Discussion in 'Microsoft ASP .NET' started by Veerle, Mar 10, 2004.

  1. Veerle

    Veerle Guest

    Hi,

    I have an aspx page with a dropdownlist and a button:
    <form id="Form1" method="post" runat="server">
    <div>
    <asp:label id="Label1" runat="server">Startdate: </asp:label>
    <asp:dropdownlist id="DateList" runat="server"
    OnLoad="LoadDates"></asp:dropdownlist>
    </div>
    <div>
    <asp:Button id="BtnBewaren" runat="server" Text="Bewaren"
    OnClick="SaveForm"></asp:Button>
    </div>
    </form>

    Every time the page is loaded, I fill the dropdownlist with items in
    the method LoadDates. When the button is clicked, then the method
    SaveForm is executed which saves the value of the currently selected
    item in the dropdownlist in a cookie.

    What I would like to do, is adjust the LoadDates method, so that at
    the end of it, the selected item is set to the value of the cookie.
    But appearantly, the LoadDates method is always executed before the
    SaveForm method. So when I change the selected item at the end of the
    LoadDates method, then the selected item is set to the previous value,
    not the new one.

    Is there a way to make sure that the SaveForm method is executed
    before the LoadDates method? Or is there a way to check in the
    LoadDates method, that the page was loaded without clicking the
    button?
     
    Veerle, Mar 10, 2004
    #1
    1. Advertisements

  2. I believe the following link will help you with your sequence issue:

    http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Veerle" <> wrote in message
    news:...
    > Hi,
    >
    > I have an aspx page with a dropdownlist and a button:
    > <form id="Form1" method="post" runat="server">
    > <div>
    > <asp:label id="Label1" runat="server">Startdate: </asp:label>
    > <asp:dropdownlist id="DateList" runat="server"
    > OnLoad="LoadDates"></asp:dropdownlist>
    > </div>
    > <div>
    > <asp:Button id="BtnBewaren" runat="server" Text="Bewaren"
    > OnClick="SaveForm"></asp:Button>
    > </div>
    > </form>
    >
    > Every time the page is loaded, I fill the dropdownlist with items in
    > the method LoadDates. When the button is clicked, then the method
    > SaveForm is executed which saves the value of the currently selected
    > item in the dropdownlist in a cookie.
    >
    > What I would like to do, is adjust the LoadDates method, so that at
    > the end of it, the selected item is set to the value of the cookie.
    > But appearantly, the LoadDates method is always executed before the
    > SaveForm method. So when I change the selected item at the end of the
    > LoadDates method, then the selected item is set to the previous value,
    > not the new one.
    >
    > Is there a way to make sure that the SaveForm method is executed
    > before the LoadDates method? Or is there a way to check in the
    > LoadDates method, that the page was loaded without clicking the
    > button?
     
    Kevin Spencer, Mar 10, 2004
    #2
    1. Advertisements

  3. Veerle

    Veerle Guest

    Thanks for your help.
    Indeed, if a do the selection of the correct dropdownlist item in the
    OnPrerender instead of in the onLoad, then the sequence is correct.

    "Kevin Spencer" <> wrote in message news:<>...
    > I believe the following link will help you with your sequence issue:
    >
    > http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
     
    Veerle, Mar 11, 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. Arulraja
    Replies:
    3
    Views:
    749
    William F. Robertson, Jr.
    Oct 17, 2003
  2. Daves

    2.0 Masterpage events before OnLoad?

    Daves, Mar 20, 2005, in forum: Microsoft ASP .NET
    Replies:
    3
    Views:
    157
    Daves
    Mar 20, 2005
  3. Daves

    any event before OnLoad?

    Daves, Mar 20, 2005, in forum: Microsoft ASP .NET
    Replies:
    6
    Views:
    327
    Daves
    Mar 21, 2005
  4. Fabio R.

    base.OnLoad called, OnLoad not executed

    Fabio R., Mar 25, 2005, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    398
    Fabio R.
    Mar 25, 2005
  5. Guest

    Get onload to occur first before Page_Load

    Guest, Jun 13, 2006, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    317
    Guest
    Jun 13, 2006
Loading...

Share This Page