OnLoad (dropdownlist) is executed before OnClick (Button)

V

Veerle

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?
 
V

Veerle

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.
 

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