Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET
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 11-Apr-13 1:36am
Comments
CHill60 at 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 at 14-Apr-13 13:08pm
   
Can you share your source code..?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
if(!IsPostback) then
//fill your drop-down 1 here
end if
 

i guess it helps you
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use
 
If Not IsPostBack Then
 
' here do u dropdown data bind work
 

End If
  Permalink  
Comments
Marcus Kramer at 15-Apr-13 9:15am
   
Please read the other answers before reposting what is already stated in an existing one.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 OriginalGriff 275
1 DamithSL 265
2 CPallini 235
3 Maciej Los 185
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100