vishalmarya
Programmer
- Aug 19, 2001
- 28
I am dynamically adding a dropdownlist to a webpage and binding its SelectedIndexChanged event to a sub.
few listitems are added to the control. the code in written in page_load . the first item comes
preselected. changing the listitem fires the associated event. but when the first item is selected , the event is not fired.
now if the same code is written in Page_Init , everything works fine.
i know that the viewstate is loaded and set after the Page_Int and before the Page_Load, but its doing for all items except the first one.
what's exactly happening here ?
( i am using asp.net 2.0 )
My code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Odl.ID = "odl1"
Odl.AutoPostBack = True
Page.Form.Controls.Add(Odl)
AddHandler Odl.SelectedIndexChanged, AddressOf EventSub
Odl.Items.Clear()
Odl.Items.Add("a")
Odl.Items.Add("b")
Odl.Items.Add("c")
End Sub
Protected Sub EventSub(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write(CType(sender, DropDownList).SelectedItem.Text)
End Sub
few listitems are added to the control. the code in written in page_load . the first item comes
preselected. changing the listitem fires the associated event. but when the first item is selected , the event is not fired.
now if the same code is written in Page_Init , everything works fine.
i know that the viewstate is loaded and set after the Page_Int and before the Page_Load, but its doing for all items except the first one.
what's exactly happening here ?
( i am using asp.net 2.0 )
My code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Odl.ID = "odl1"
Odl.AutoPostBack = True
Page.Form.Controls.Add(Odl)
AddHandler Odl.SelectedIndexChanged, AddressOf EventSub
Odl.Items.Clear()
Odl.Items.Add("a")
Odl.Items.Add("b")
Odl.Items.Add("c")
End Sub
Protected Sub EventSub(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write(CType(sender, DropDownList).SelectedItem.Text)
End Sub