Click here to Skip to main content
16,019,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone,

Page Structure
Page -> Place Holder -> web User control -> Dropdownlists

This is my Page Elements. There is click event to generate new webUserControl and place it onto PlaceHolder.
Now my Problem is that
I have three Dropdownlist inside webUserControl
and all values of dropdownlist populates from xml files.

Here is some Images to clarify my Problem
"All are inside WebUserControl which will created dynamically on the occurance of Click event"

1) suppose this is my first Drop down list -> i) DropdownlList

2) Now suppose I am selected "verb" option from dropdownlist1 automatically other dropdownlist2 will be visible and populates items in it according to dropdownlist1 selection


3) **Now main Problem starts here, **
when I am clicked on "Auxiliary" option, I am supposed to get index of Auxiliary text. It is 3. but it always returns index 0

this dropDownList does not hold the selected value.

Please give suggesions to resolve this problem.
Thanking you
Posted
Comments
CHill60 11-Apr-13 6:44am    
Sounds similar to an issue I had where the page was refreshing before I captured the selectedIndex - if I recall I had to check Page.IsPostBack
vinodkumarnie 14-Apr-13 13:08pm    
Can you share your source code..?

The problem is you are filling your 1st drop-down list in form load and every time some event happens it loads the form i guess u have not kept update panel so again it fills your first drop down and causes selected index changed event to fire which makes your dropdown2 selected index 0 again and again.


so my suggestion is you keep filling of your first drop down as following in form load

C#
if(!IsPostback) then
//fill your drop-down 1 here
end if



i guess it helps you
 
Share this answer
 
v2
use

If Not IsPostBack Then

' here do u dropdown data bind work


End If
 
Share this answer
 
Comments
fjdiewornncalwe 15-Apr-13 9:15am    
Please read the other answers before reposting what is already stated in an existing one.
Thank you so much to all.
Mr. Raj Sir You are absolutely right. controls getting refresh on each page load event.
even I applied update panel in my web use control but no use.

Mr. Babu Sir, Sorry but It will not work for my control.

I have solved my problem.

Actually , as I said I am creating my dynamic control in the occurrence of click event and placed in place holder.
and placeholder clears on each postback and then again load then web User Control. Due to this dropdownlist2 which dependent on dropdownlist1 gets refresh and cleared all values.

Solution :
write OnInit () method and inside that call function for filling up the values of dropdownlist1.
Postback cant reflects on dropdownlist1.

It works fine.

thanking you sir
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jul-13 2:29am    
Not an answer, should be deleted.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900