Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cant't access the Controls Present In A User Control In A Page Which Includes Master Page.

I Have A Masterpage A.Master
I Have A Page A.aspx which include masterpage
In A.aspx i have a button named Save & Some Usercontrols like myusercontrol1,myusercontrol2 etc...

I need that when i click the save button i want to access the controls present in that user controls & get the value present in.

What I have tried:

i registered those usercontrols in web.config file.
i fired the click event of save button & write the following code
myusercontrol1 obj = new myusercontrol1()
Gridview grvuserdetails=(Gdidview)obj.findcontrol("GridView1").

But The Value In obj & grvuserdetails becomes null.
Posted
Updated 4-Apr-16 23:51pm

 
Share this answer
 
HI Arya
if you try to find the control in an empty object (new instance) then you will get null only.
C#
myusercontrol1 obj = new myusercontrol1()

instead, use the user control Name (which is defined in the aspx file )
eg: if the control name is userControl1 then the code wil be like
C#
Gridview grvuserdetails=(Gdidview)useControl1.findcontrol("GridView1")
 
Share this answer
 
C#
ContentPlaceHolder CP = (ContentPlaceHolder)this.Page.Master.FindControl("ContentPlaceHolder1");
UserControl userControl= (UserControl )CP.FindControl("useControl1");
Gridview grvuserdetails= (Gridview)userControl.FindControl("GridView1");
 
Share this answer
 
Comments
ARYA JAGANNATH 5-Apr-16 5:54am    
Thanks Its Working properly Now ....
Thanks a lot !!!

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