Hello, All.
I have SELECT on my WebForm, marked as [Run as Server Control].
<SELECT id="Select1" name="Select1" runat="server">
<OPTION value="AAA" selected>AAA</OPTION>
</SELECT>
In Page_Load new item inserted into Select1:
private void Page_Load(object sender, System.EventArgs e)
{
Select1.Items.Add("BBB");
Select1.Items[SortMode.Items.Count - 1].Value = "BBB";
...
}
And finally, here is
private void Select1_ServerChange(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine(Select1.Value);
}
Now, if I select item "AAA" and submit form - I see "AAA".
But when I select "BBB" - I still see "AAA".
Why this occur? How can I solve this problem?
Thank you for your time,
Alex.
Craig Deelsnyder - 20 Jul 2005 03:24 GMT
> Hello, All.
>
[quoted text clipped - 24 lines]
> Thank you for your time,
> Alex.
Add a check for IsPostBack; when you alter the items collection, it loses
its selectedindex. So wrap you Page_Load body with
if (!IsPostBack)
{
//...do your stuff
}

Signature
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
AC - 20 Jul 2005 09:21 GMT
Hi, Craig
Thank for you tip! I have moved my code into pages OnInit method - and now
all is ok.
Alex