Airshow:
Works fine for me. Are you sure there are 6 items in the dropdownlist? if
you have 5 or less items, doing selectedindex=5 won't work :)
Also, you say "next time in response to some client action" what's the
client action? Are they simply hitting "f5" to reload the page or are they
hitting an control which causes postback?
if you take this basic example:
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" Runat="server" />
<asp:Button id="btn" Runat="server" />
</form>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e) {
if ( IsPostBack )
DropDownList1.SelectedIndex = 5;
else {
FillDropDownList( DropDownList1 ); // some method to fill
DropDownList1.SelectedIndex = 0;
}
}
private void FillDropDownList(DropDownList ddl) {
ddl.Items.Add("1");
ddl.Items.Add("2");
ddl.Items.Add("3");
ddl.Items.Add("4");
ddl.Items.Add("5");
ddl.Items.Add("6");
}
</script>
it works.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Airshow" <ai*****@hotmail.com> wrote in message
news:em****************@TK2MSFTNGP11.phx.gbl...
Hi,
I have very simple Page_Load code in some code-behind class in ASP.NET (v.
1.1):
private void Page_Load(object sender, System.EventArgs e)
{
if ( IsPostBack )
DropDownList1.SelectedIndex = 5;
else
{
FillDropDownList( DropDownList1 ); // some method to
fill values in list
DropDownList1.SelectedIndex = 0;
}
}
Everything is fine with selection first time Web page is loaded -- first
item in the dropdown list is selected. Problem is that selection does not
change to 5 when the page is loaded next time in response to some client
action -- it is always 0 in client side when page is reloaded. Same
problem goes for other controls in the form -- neither labels nor text boxes texts
can be changed dynamicaly in Page_Load. Any help please?
Airshow