Click here to Skip to main content
15,902,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have developed a web application with multiple pages and user controls. However, I am facing an issue on one of the user controls.

The Background:

The User Control has multiple textboxes, lables and dropdowns. there are four dropdowns, which are dependent on one another. They are Country, State, District and City. On country is selected, state gets filled and on State is selected, district gets filled and so on.

the dropdowns have autopostback set to true.

This User control is used TWICE on the same page for Permanent Address and communication Address.

The Problem:

If the country is changed in one of the instances of the user control, the selection on other usercontrol is reset to selectedIndex 0.

I tried with Enableviewstate, but of no use.

Request:

Any quick guidance on this is highly appreciated.
Posted
Comments
s#@!k 28-Jan-14 8:00am    
keep all the dropdowns in update panel.
ZurdoDev 28-Jan-14 9:32am    
Sounds like you are databinding them in the Page_Load event without checking for IsPostBack,
shivaprasadk 28-Jan-14 23:31pm    
@s#@!k : I tried keeping the user control within the Update panel. But of no use.Should I use update panel only for Dropdowns within user control?
shivaprasadk 28-Jan-14 23:33pm    
@RyanDev : No Sir, I have Page_load with if(@isPostback) and the dataloads within it.

also, I dont understand why, the selection of item in one dropdown of user control instance, fires the onselectedindexchanged event of same dropdown in other instance of user control.
Karthik_Mahalingam 29-Jan-14 0:55am    
post your code..

where are u placed this used control code to bind ? is it in pageload check for it will placed inside !ispostback

correct format

if(!ispostback
{
your code...
}
 
Share this answer
 
Thanks to all for taking your time and trying to help me.

Initially I thought it might be the issue of Usercontrol and DropDownList.

However, after deeper exercise, I could succeed in getting control of the DropDownList.

The Error was in:

The coders had used Property for assigning value to DropdownList and to retrieve value.

Though the retrieval part was working fine, the assigning part was screwing the process. I changed it and now it is working fine.


The Property code where issue was there:
C#
public string GetStateID
       {
           get
           {
               return cmbState.SelectedItem.Value.ToString();
           }
           set
           {
               cmbState.SelectedItem.Value = value;
           }
       }


I have commented the set{} Part and used separate function to assign value to the DropdownList.

Now it is working fine.


Thanks to all for the suggestions and guidance.

Regards
 
Share this answer
 

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