Click here to Skip to main content
15,664,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project i have added usercontrol on page load . In this usercontrol i have two dropdown lists present in it. Now when it is first time loaded it works fine on selected index change. But when i add one more user control by clicking add button than the drop down does not populate.on the page load of user control i have populated dropdown list when it is Ispostback.now here if i remove the isposback than the both ddl will show all the data. which will not change on selected index change.
Posted
Comments
manognya kota 7-Feb-12 6:56am    
could you please post the code for how are you adding the usercontrol and how are your pageload of user control.
Member 8532756 7-Feb-12 23:51pm    
//This is the code for usercontrol which i have written
protected void Page_Load(object sender, EventArgs e)
{

if (IsPostBack)
{
//Binding the years to DropDownLists.
string date = System.DateTime.Now.ToString("yyyy");
for (int i = 1981; i <= int.Parse(date); i++)
{
ddlFromYear.Items.Add(i.ToString());
ddlToYear.Items.Add(i.ToString());

}


//Binding University to Dropdownlist

//Binding Colleges to Dropdownlist

//Binding Qualification to Dropdownlist

}
}
//on page load of aspx page one usercontrol is loaded as abydefault and second Usercontrol is added on button click
//And for aspx page i have added UC on add button click its code is as follows:

protected void btnAddAca_Click(object sender, EventArgs e)
{
//When candidate click on Add button...
//add new user control
Control ucNew1 = LoadControl("~/usercontrols/UpdateAcadamicDetails.ascx");

HtmlGenericControl tempDiv1 = new HtmlGenericControl();
tempDiv1.Attributes.Add("runat", "server");
tempDiv1.ID = "divAcaControl" + int.Parse(ViewState["COUNT2"].ToString());
tempDiv1.Controls.Add(ucNew1);
//PHAca is a placeholder on aspx page
PHAca.Controls.Add(tempDiv1);
}

********************************************************************




I have used
if(!IsPostBack)
{
// code here
}

but only first time the ddl will be populated but for second time it will not show any data.......
Member 8532756 8-Feb-12 0:02am    
In the above code i have used update panel for placeholder on the .aspx and even i have used trigger in update panel but than also it wont work.For the first time the above code is running fine but when one more usercontrol is it does not show any data in ddl.now here i tried to remove Ispostback at usercontrol .cs page than also it wont work.
Anuja Pawar Indore 8-Feb-12 3:15am    
Use improve question link and paste your code there with in pre tag
ZurdoDev 7-Feb-12 16:45pm    
Need to see your code to understand what you are doing.

1 solution

Hi,
Please set if condition to not postback.
like,
C#
 if(!IsPostBack)
{
// code here
}
 
Share this answer
 
v2
Comments
Member 8532756 9-Feb-12 3:24am    
only first time the ddl will be populated but for second time it will not show any data

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