Am I doing this correctly?
I have two dropdowns. The first is populated on form load, and it is a trigger for an updatepanel that contains the 2nd dropdown.
When I change the value in the first dropdown box, it triggers the 2nd one's updatepanel, which populates it.
However, when I select a value in the 2nd dropdownbox, it triggers itself and repopulates... so if I select the 2nd or 3rd item in the dropdown, it repopulates and selects the first item again.
Am I doing something wrong, or is this normal? Should I put the first dropdown into an updatepanel instead and have it trigger itself, and in its own trigger, populate the 2nd listbox?
It appears that changing the value in the second dropdown is causing a postback, which it then sets the value to the default or first value. Try setting the dropdown's AutoPostBack property to false and EnableViewState to true.
Use the ASP.NET Ajax Control Toolkit CascadingDropDown instead.
EDIT: You need to set your UpdateMode=Conditional and control when your UpdatePanel's should update, by calling UpdatePanel2.Update().
I had this problem once.
This is a problem for update panel plus dropdown autopostback
By default ViewState for page is stored,so you do not need to change ViewState for control.
First,Change your UpdatePanel's UpdateMode property to Conditional UpdateMode="Conditional".This ensures that you can control postback since your dropdown always postback when you set AutoPostBack to true.
Second is in your method which you bind datasource into dropdown,after databinding is done.Update your panel by calling Update method of UpdatePanel updPanel.Update(); by
dropdown.DataSource = source;//I presume
dropdown.DataBind();
updPanel.Update();
Hope this helps.
Related
Am using DropDownList controls in ASP.NET binding values from SQL table. Some control have only one value, some control have more than one value. The SelectedIndexChanged event is not fired which control have only one value.
I set AutoPostBack=true and 0th item as select. Even though that event is not fired for that control?
SelectedIndxChanged event fires only if you change your selection and your DDL has AUTOPOSTBACK true.
If you have only one value in DDL then you don't need this event , you can write your desire code after you bind the dropdown on server side itself.
If you are not binding DDL from server side you can write your code on or after Page_Load event there you'll get the selected index
SelectedIndexChanged only fires when the selection has changed. If there's only one item in the dropdown list, you can never get this to fire (there's nothing to change to).
That being said, you can add a blank item to the top of the list (index 0), with the following at the top of the code where you populate the dropdown list:
MyDDList.Items.Add("");
That way you CAN choose something even with your one item.
Respected sirs
I am using a DropDownList control and binding it to a LinqDataSource.
According to the selection of the mentioned DropDownList, I need to bind another DropDownList control.
I have handled the SelectedIndexChanged event for first DropDownList. When this SelectedIndexChanged occurs, page is getting refreshed. To prevent page from beend refreshed, I am using an UpdatePanel control. But, still the second DropDownList not loading.
Please give me a solution.
Thanks
Saravanaa
Place the second DropDownList inside the UpdatePanel.
You may want to consider using CascadeDropDown too.
I have created a label and a dropdownlist. The label has the dropdownlist as associated id.
If I click on the label and then uses the mouse up or down the dropdownlist creates a postback for each click. This is quite anoying and doesn't happen if you click on the dropdownlist and uses key-up or key-down, or if you uses another browser than IE.
Is it possibel to fix this, so you can use key-up and key-down without causing a postback, and first on the enter-key creates the postback (as it does if you click on the dropdownlist and not label)?
Set DropDownList.AutoPostBack to false.
Set the AutoPostBack property to false.
See the documentation.
I forgot to mention this asp.net 2.0.
The user control has a unique id and it is loaded in the PageLoad event.
The user control is loaded into a panel and the panel is inside of a webpart.
The dropdown has autopostback set to true.
EnableViewState = true on the dropdown.
The ListItems are created in the dropdowns pre-render event method.
This is why I don't understand why it is not firing, the dropdown is the only thing that causes postback on this user control.
The event methods for the dropdown should occur since the user control is loaded in the page load method on postback again right?
Make sure there is no OnLoad or PageLoad event that is rebinding the datasource of the dropdown list. Rebinding the data with a new set of data may cause the clickhandler to not ever get executed.
make sure you have if (!Page.IsPostBack) around dropdownlist.datasource = and dropdownlist.databind()
I am not sure if this is your problem, but it is the most common.
Try with EnableViewState set to
true for the DropDownList
If the ViewState is set to false, on post back the selected Index gets back to default which is normally the first Item. First item, if selected, does not cause SelectedIndexChange event to fire
I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.
How do I make my dropdowns handle SelectedIndexChanged instantly?
P.S. It's a classic question I have answered too many times, but it seems no one asked it before on stackoverflow.
Setting the AutoPostback property to true will cause it to postback when the selection is changed. Please note that this requires javascript to be enabled.
You need to set the AutoPostBack property of the list to true.
Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.
Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack. This will cause the event not to fire.
The same is also true of repeaters and ItemCommand events.
if you are populating the dropdown list during page load then each time the page postback it will reload the list thus negating your postback method.
you need to be sure to load the dropdownlist only if (!ispostback)
Set the AutoPostBack property of DropDownList to true.