AutoPostBack with ASP.NET webforms

S

somersbar

im trying to get a selected item from a dropdownlist(which is populated
from a microsoft access database) to appear in a textbox. i have set
autopostback to true for the dropdownlist, but no matter what item i
select from the list, its always only the first item in the list that
gets sent to the textbox. Do i need to use session variables or
something to store the values and then reload them in the pageLoad
fuction. i tried this but it didnt seem to work. can anyone help
please?

this is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AreasDataSet11.Clear()
OdbcDataAdapter1.Fill(AreasDataSet11)
DropDownList1.DataBind()
End Sub



Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
TextBox1.Text = DropDownList1.SelectedValue
End Sub
 
J

Jacob

I can imagine that the selected index gets reset when you refill your
dropdown list. Only do the databind if the page is not postback.
 
J

Jacob

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
AreasDataSet11.Clear()
OdbcDataAdapter1.Fill(AreasDataSet11)
DropDownList1.DataBind()
End If
End Sub

Page Load fires before any events so by the time you get to the event
the index has been reset.
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,811
Latest member
SaulFernan

Latest Threads

Top