conditional postback
-
I've tried too many things to make this work and can't quite get it right, so here it is: I have a VB.Net webform with a textbox(txtZip) that accepts a ZipCode, it's set to autopostback. Upon that autopostback, it populates a dropdown with all cities that are associated with that ZipCode. There are other textboxes on the page that cause postback and some buttons too. I only want the dropdown to load when txtZip caused the postback, otherwise I lose which city was selected in the dropdown. Anyone out there have any true-tested code that will work? Thanks for any help!
-
I've tried too many things to make this work and can't quite get it right, so here it is: I have a VB.Net webform with a textbox(txtZip) that accepts a ZipCode, it's set to autopostback. Upon that autopostback, it populates a dropdown with all cities that are associated with that ZipCode. There are other textboxes on the page that cause postback and some buttons too. I only want the dropdown to load when txtZip caused the postback, otherwise I lose which city was selected in the dropdown. Anyone out there have any true-tested code that will work? Thanks for any help!
store the value in the view state string cityname = "Houston"; string cityname = ""; now in the postback if( IsPostBack ) { cityname = Convert.ToString( cityname ); combo.Text = cityname; } in the SelectedIndexChaged event ViewState["city"] = combo.text; What I'm doing is after an item is selected I save the value to the viewstate. Then after postback I reset the value that was saved in the viewstate 1 line of code equals many bugs. So don't write any!! -- modified at 14:48 Wednesday 1st February, 2006
-
store the value in the view state string cityname = "Houston"; string cityname = ""; now in the postback if( IsPostBack ) { cityname = Convert.ToString( cityname ); combo.Text = cityname; } in the SelectedIndexChaged event ViewState["city"] = combo.text; What I'm doing is after an item is selected I save the value to the viewstate. Then after postback I reset the value that was saved in the viewstate 1 line of code equals many bugs. So don't write any!! -- modified at 14:48 Wednesday 1st February, 2006
-
Whenever I select the city in the dropdown, it reloads and I lose which city I selected, what am I doing wrong here?: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Page.IsPostBack Then ddCity.SelectedIndex = ViewState("ddI") End If End Sub Private Sub ddCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddCity.SelectedIndexChanged ViewState("ddI") = ddCity.SelectedIndex End Sub Thank you for your continued support!
-
Whenever I select the city in the dropdown, it reloads and I lose which city I selected, what am I doing wrong here?: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Page.IsPostBack Then ddCity.SelectedIndex = ViewState("ddI") End If End Sub Private Sub ddCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddCity.SelectedIndexChanged ViewState("ddI") = ddCity.SelectedIndex End Sub Thank you for your continued support!
If not Page.IsPostBack Then ... End if Otherwise it will populate for every postback.
-
Whenever I select the city in the dropdown, it reloads and I lose which city I selected, what am I doing wrong here?: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Page.IsPostBack Then ddCity.SelectedIndex = ViewState("ddI") End If End Sub Private Sub ddCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddCity.SelectedIndexChanged ViewState("ddI") = ddCity.SelectedIndex End Sub Thank you for your continued support!
this can do it, but I dont advise ddCity.AutoPostBack = false; The reason why is this: When you select the item. It forces a postback before it fires the method. It runs your Page_Load, then runs your selected index somewhere in either events you are overriting the new value. You might be cahnging it from another event. For instance, in aither event you might be setting this value so its getting overidden. Put a breakpoint in the select changed value and then open the Debug --> Other windows --> Locals. Inspect the drop down list and check the value. Do this at post back. It should be fine. Although, looking at it. If you take out the entire if postback statement. It should work just fine. 1 line of code equals many bugs. So don't write any!!