Is it possible to get control values from a User Control in aspx page during Page_Load event

Posted by Avravi under ASP.NET on 7/16/2013 | Points: 10 | Views : 1166 | Status : [Member] | Replies : 2

I am working on a User Control and I am facing an issue. Below is the scenario.

--> I have an user control (an Application Form), which gets the data from Database and populates the form based on Application ID which we set from an aspx page.

--> An aspx page uses this user control. In this aspx page, in addition to the User Control, I have some additional controls like dropdowns, textboxes etc., which needs to be populated on Page_Load (the values for these additional controls belong to the same application form as in User Control and needs to be retrieved from the database).

--> Here the issue is, I want to query the database only once (which I am already doing in the User Control). I am storing the values for the additional controls (in aspx page) in hidden fields in the User Control, so that I can access them in aspx page. But, unfortunately I am not able to access those values because, the Loading of User Control in the aspx page and the loading of additional controls in aspx page happens at the same time that is during the Page_Load event of the aspx page.

Is there any work around for this?

One solution I can think of is to have those additional controls in User Control itself and pass some parameter to the User Control, based on which I can Hide or Unhide those controls. In this way we need not worry about populating the additional controls in ASPX page with values. But, I don't want to do this because I have many additional controls (Varies from page to page where I use User Control) and so many pages and I don't want to write too much of code in User Controls to Hide and Unhide controls.

Thanks in advance for your help.




Posted by: Avravi on: 8/15/2013 [Member] Starter | Points: 25

Hi Aswini,

Thanks a lot for your reply. These links are helpful.

However, I found a solution for this. I used Page_PreRender event. It worked fine.



Avravi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response