Reputation: 5506
I have the control dropdownlist
which has been loaded inside the template column of RadGrid
.
While loading I have set AutoPostBack='True'
for dropdownlist
and also created the event SelectedIndexChanged
.
DropDownList ddlConditions = new DropDownList();
ddlConditions.ID = "ddl" + name;
ddlConditions.AutoPostBack = true;
ddlConditions.SelectedIndexChanged += new EventHandler(ddlConditions_SelectedIndexChanged);
My question is while i change the selected index of dropdownlist
the event SelectedIndexChanged
is not getting triggered.
Can anyone help me to solve this problem?
Thanks in advance.
Upvotes: 1
Views: 2769
Reputation: 382
I can suggest you to check the place where you have created DropDownList. Dynamic controls should be added on OnInit or at least on OnLoad. After OnLoad finishes executing ASP.NET starts processing control's events and values.
My question is while i change the selected index of dropdownlist the event SelectedIndexChanged is not getting triggered.
Answer: because you have created DropDownList after the events have been processed.
Upvotes: 1
Reputation: 772
Usually this caused by a page life cycle problem
. When your index changed event of Dropdownlist fires the control doesn't exist to bind it on the postback.
Example:
-> MyEvent fires. -> Drop-down created. -> Event Handler specified. -> Index Changed event triggered. Page reloads. Drop-down not found, cannot fire.
So you have to ensure that the drop-down is created before
.NET attempts to handle the event.
Please refer this answer for more information regarding this type of issue and life cycle.
Upvotes: 1
Reputation: 12037
Is the page posting back? If so, you'll need to make sure that the control is recreated on the page on every postback.
If it's inside the usual if(!IsPostBack)
block, then put it outside - Usually, it's prudent to create controls in page_init
as well, but that can depend on your specific setup.
Upvotes: 0