where is your control you are trying to find, is it in the parent master page or child master page. if its in the parent master page then you can find the control by using like
Master.FindControl("label1") and if its in the child master page you can find like below Master.Master.FindControl("label1").
now if its inside the the contentplaceholder, first find the contentplaceholder and then find the control.
hope this helps. let me know if you need any more help.
Thanks
Keyboard not found. Please Press < F1 > to RESUME
Please Remember to Mark as Answer for the post(s) that help you.....so it can help others......Thanks
I have tryed everything i could think of but still no result.
Mij aspx page inherits from twocolumn.master
The twocolum.master inherits from master.master
so when im in my user control there's no way i get to the listview in the parent page.
so findcontrol in page, parent, master, master.master. It's all not working. I don't know what the problem is yet. But i will let you know if i do figure this one out.
ContentPlaceHolder cp = (ContentPlaceHolder)Page.Form.FindControl("ContentPlaceHolder1");
Panel p = (Panel )cp.FindControl("hidden1");
Label l = (Label)p.FindControl("Label1");
Label2.Text = l.Text;
l.Text = "nitin";
Awesome!! This was great! Thanks, man! Only thing: I added a "this" in front of Page.Form..... on that first line. Don't know if I needed to or not, but it worked.
talsja
Member
69 Points
53 Posts
Parent.FindControl always null on usercontrol (ascx)
Jan 13, 2009 02:28 PM|LINK
Hello,
I'm struggeling a little with the following:
I use asp.net 3.5 with nested masterpages.
I have a content page (aspx) from TwoColumn.master.
On this page i have an ajax tabcontrol with 3 tabpanels.
Inside tab1 i have a listview named lvAllContacts.
Inside the second tabpanel i have a reference to a usercontrol (NewContact.ascx).
Inside the NewContact.ascx there's a webform with a bntSubmit.
when the btnSubmit Click event is fired i validate the form and save the data to the database.
When no problems occure i want to databind the ListView op the Parent page like this:
ListView lv = (ListView)Parent.FindControl("lvAllContacts");
lv.Databind();
Now the lv is always null.
I tried alsow this. Page.Parent
This alsow gives null.
Then i tried going to go to the ContentPlaceholder on the masterpage and then go to the parent page, but alsow this returns null.
Does anybody know a solution for this one?
Thanx a lot
talsja
Member
69 Points
53 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Jan 14, 2009 11:03 PM|LINK
Nobody an idea?
When im in the parent page i can reach all controls in the ascx page but in child page i can't see the controls in the parent page.
Strange. Oke then i have to work with an workaround.
Thanx
nitindhiman
Participant
953 Points
164 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Jan 15, 2009 12:58 PM|LINK
hi,
I don't hv any exp on 3.5 but in 2.0 also u hv to find the control following way....
i did it following way....
ContentPlaceHolder cp = (ContentPlaceHolder)Page.Form.FindControl("ContentPlaceHolder1");
Panel p = (Panel )cp.FindControl("hidden1");
Label l = (Label)p.FindControl("Label1");
Label2.Text = l.Text;
l.Text = "nitin";
and finally i got the desired results.
hope it helps, but don't forget to mark answer....
bbyePlease Mark Answer If Helped....!!!!
novicehere
Contributor
4654 Points
854 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Jan 15, 2009 01:14 PM|LINK
Hello There,
where is your control you are trying to find, is it in the parent master page or child master page. if its in the parent master page then you can find the control by using like
Master.FindControl("label1") and if its in the child master page you can find like below Master.Master.FindControl("label1").
now if its inside the the contentplaceholder, first find the contentplaceholder and then find the control.
hope this helps. let me know if you need any more help.
Thanks
Please Remember to Mark as Answer for the post(s) that help you.....so it can help others......Thanks
talsja
Member
69 Points
53 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Jan 19, 2009 12:36 PM|LINK
Hello,
I have tryed everything i could think of but still no result.
Mij aspx page inherits from twocolumn.master
The twocolum.master inherits from master.master
so when im in my user control there's no way i get to the listview in the parent page.
so findcontrol in page, parent, master, master.master. It's all not working. I don't know what the problem is yet. But i will let you know if i do figure this one out.
Thanx all
Dogbert1234
Member
2 Points
4 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Sep 06, 2009 02:50 AM|LINK
Generally you would add in your control
<%@ Reference Page="/THE_PAGE_YOUR_TRYING_TO_ACCESS.aspx" %>
and in the control .cs file
( this.Page as THE_PAGE_YOUR_TRYING_TO_ACCESS).YOUR_METHOD_OR_SETTING();
If that makes sense
navyjax2
Member
88 Points
45 Posts
Re: Parent.FindControl always null on usercontrol (ascx)
Jun 29, 2012 12:21 AM|LINK
Awesome!! This was great! Thanks, man! Only thing: I added a "this" in front of Page.Form..... on that first line. Don't know if I needed to or not, but it worked.