Accesing controls on the MasterPage from UserControl in Umbraco...
//UMB Experts,
//Attempting to access HTMLGenericControl - <li> Control myControl1 = FindControl("TextBox2"); Control myControl1 = Page.FindControl("TextBox2"); Control myControl1 = this.Page.Master.FindControl("TextBox2");
The above method doesn't work. Any help greatly appreciated.
The major difference between that and your requirements is that your <li> element isn't a server element. Now I've always hated the FindContorl method because I could never really tell when it will find which controls and from which control to start. Couple of ideas:
- any chance you can make that <li> into a proper server control that you can just reference on the master page?
- add code-behind files, add a method on your master page (the one with the control on it) that will take e.g. text as an argument and the client id of the control you are looking for. The method will then find the control and do whatever you want to do with it. The difference is that you call the method on the master page which does all the magic instead of doing the magic on the nested masterpage
Accesing controls on the MasterPage from UserControl in Umbraco...
The above method doesn't work. Any help greatly appreciated.
Hi Kevon
it the above code placed in your masterpage?
/Jan
No it's in the UserControl... should I move it directly to the MasterPage?
Hi Kevon
Well I'm not quite sure how your user control is structured...
But I think you need to have this in the top of your user control
<%@ Control Language="C#" AutoEventWireup="true" %>
and then before the content in your user control you should have this:
<script language="c#" runat="server">
//your c# code goes here
</script>
Could this be what you're after? :-)
/Jan
Hi Kevon,
check out the blog post I just published: http://farmcode.org/post/2011/01/28/Creating-code-behind-files-for-Umbraco-templates.aspx
The major difference between that and your requirements is that your <li> element isn't a server element. Now I've always hated the FindContorl method because I could never really tell when it will find which controls and from which control to start. Couple of ideas:
- any chance you can make that <li> into a proper server control that you can just reference on the master page?
- add code-behind files, add a method on your master page (the one with the control on it) that will take e.g. text as an argument and the client id of the control you are looking for. The method will then find the control and do whatever you want to do with it. The difference is that you call the method on the master page which does all the magic instead of doing the magic on the nested masterpage
Hope that helps,
Sascha
is working on a reply...