dropdown selectedindexchanged issue within modalpopup extender - c#

I'm having a dropdown in a ModalPopupExtender. The dropdown values are updated dynamically.
The problem is While clicking on the button in modal popup...The dropdown values was refreshed. So I tried to take the selected value of dropdown within the sectedindexchanged event. But If I put breakpoint with this also the control is not coming.
Can anyone tell me the fix for this?

SelectedIndexChanged is event triggered when the selection is changed, not when you change the items in the dropDown. for that you may use DataSourceChanged if you change the dataSource property or other, or other events, depend on what your code do ( please share it).

Related

Is this possible to get dynamic dropdown's selected value before SelectedIndexChanged event?

I am creating a set of tables, dropdowns, buttons, labels dynamically on OnInit() event on the basis of list of objects( fetched from database). I have bound events with these dynamic controls as well.
On dropdowns_SelectedIndexChanged event I have to populate my list of objects again from database on the basis of selected value and recreate these tables, labels again.
First time dropdown selection is working fine for me, but as soon as I am recreating control here on dropdowns_SelectedIndexChanged, the event of dropdowns are not bound (as it is compulsory to add dynamic controls on OnInit() to bound events with them) .
Now for an alternative I am trying to get dropdown's selected value on any Page event near by pre_render() so that I could recreate my controls there with updated objects List without any dropdowns_SelectedIndexChanged event.
Any help will be appreciated. Thanks in advance.
Yes, here is one nasty way!
You can index the Request.Form["__EVENTTARGET"] that should get you what your after.
BUT I wouldn't necessarily/always recommend it. Even when adding controls dynamically you should be able to get the selected value, in the correct event handler. It's probably owing to where you are adding the control in the page lifecycle.

prevent of firing Repeater_ItemDataBound event in AspxGridView Edit mode in Row_Updaing Event (Wow!!!)

Hello everybody !
In .net , i have a Devexpress control [aspxgridview ]... in edit mode of this control , i fill a repeater that has ItemDataBound event
when i press on update btn (of grid) , itemdatabound calls & works very well & i choose an item (is a radioBtn)
BUT
when i press updateBtn , that event i said (itemdatabound) fires again &
my selected item CLEAR (i'm crying)
please help me dears!!
thanks in advance
mohammad
Since your button is doing a postback, you need to have all items on your page re-created and re-databound in order for them to be displayed. Without having much to go on, it sounds like you need to hold onto your selected item so you can re-create/re-databind the Repeater with every post back.
I may be able to be of more help if you post your code.

How to access value of list box?

I have update panel which gets updated on button click event. Out of the update panel,there is list box. When user clicks on the button which is placed inside update panel, at that time I want to retrieve selected items from the list box, but when I click the button, the selected index of list box is showing zero even if I select any item. I cant understand why it is happening so. Perhaps it is because partial update is taking place. How to tackel with this problem??
When you click the button, your page does a postback to the server on page_load and I think you are binding again. That's why the previous selection cleared. You should take care of the IsPostBack Condition while binding data to the listbox.

Dynamics controls lost on postback

This old chestnut again.
My page is constructed as follows; I have a dropdownlist which is databound on first load. When the user selects a value from this, a postback is performed which then databinds a repeater control.
The ItemTemplate of this repeater control contains a placeholder control. In code behind in the ItemDataBound event of the repeater, I am adding two controls dynamically to this placeholder, a hiddenfield and a checkbox.
When the user clicks the save button, I then want to iterate over all those dynamically created hiddenfields and checkboxes and determine their values. However when the user clicks the save button, those controls no longer exist as shown in the page trace.
I know this is a lifecycle issue and the articles I've seen on this suggest using Init methods to dynamically create your controls but I can't because of the way my page works, e.g. the repeater control only appears and binds after a value is chosen from the dropdownlist.
What do I need to do to maintain the dynamic controls through the postback caused by clicking on the save button?
The problem is when you hit the save button probabily you dont re-bind the repeater and the controls you have added at run time withint the ItemDataBound event are not longer available(because they don't exist anymore)
Why don't you add those control at design time using the Eval function the set up the value of the hidden field?
You just don't create them dynamically just on the on selection change of the drop-down set visibility true or false for the repeater that will solve your problem.on post back you have to again create those control as they are Dynamically created.

Obtaining selected item, value or index from drop down list in formview after button press

I have a formview with an insertion template. In this template there is a drop down list with a number of items I want users to be able to select from. Beside the drop down list there is a button which I am using to add the selected item from the drop down list to a gridview which also exists in the insertion template.
My problem is that when I click the button to add the selected item from the drop down list the selected item, index or value from the drop down list are not available. I am using a OnClick event handler to catch the event from the button click but I suspect there is some kind of refresh of the template going on here which I am not understanding as nothing appears to be accessible from the button event handler. I don't believe a postback is occurring as I have disabled the CausesValidation property for my button.
It seems like you are binding your DDL on postbacks as well. If the ddl data isnt hardcoded and you have the call for your ddl databind function in the Page_Load, you need to call the function like this to ensure it is not bound on postback:
if(!IsPostBack)
{
BindDDL();
}
Otherwise we need more information to help you and please post your code.
If you are clicking an asp:Button with an OnClick eevent attached to it then you are posting back to the server, no matter whether or not CausesValidation is true or not.
Are you binding data to the DropDownList? If so and you are rebinding it on postback then you'll not have the selected item you're expecting.
Can you paste us the code here?
I would have to see the code, but it sounds like you are getting a rebind prior to pulling the chosen items. One way to examine this is to add a watcha nd then make sure you code in the various ASP.NET events and then watch.
Without seeing what you are doing in code, I cannot tell if this is a drag and drop anomoly or something you have coded in. But the symptoms you are describing fits the typcial bind in Page_Load scenario, which is what jmein was aiming at.
So it turns it out it was all my fault. The formview control I have is contained in a panel which did not have view state enabled. This was preventing the drop down list from remembering the item I had selected it seems.
Thanks all for your comments and suggestions.

Categories