Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to check if a user control is loaded for the first time in a page? Ispostback is always true for the usercontrol.
Posted
Comments
ZurdoDev 2-Oct-13 22:06pm    
Post the relevant code so we can see what you are talking about.
Member 3521466 2-Oct-13 22:23pm    
I have a usercontrol named Employees.ascx in my application.I am loading it dynamically in an aspx page using the code


ASP.Employees_ascx emp=new ASP.Employees_ascx();
panel.controls.add(emp);


In the Employees.ascx page,in Page_Load I have the code

If(!Ispostback)
{
LoadEmployees(); //to load the dropdownlist
ViewState["Sort"] = "";
}


The above code inside the if condition is never getting executed since Ispostback is always returning true.

Please advise.
ZurdoDev 2-Oct-13 22:59pm    
When adding controls dynamically you should do it in the pages On_Init() event.
Naresh1277 3-Oct-13 0:54am    
For the User Control IsPostback() wont be working in the Page_Load()
Azee 3-Oct-13 1:18am    
Do you have to add the UserControl dynamically? In this case code inside If(!Ispostback) will never get executed since your above code is executed afterwards.

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