Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevon K. Hayes 255 posts 281 karma points
    Jan 28, 2011 @ 20:11
    Kevon K. Hayes
    0

    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.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 28, 2011 @ 20:14
    Jan Skovgaard
    0

    Hi Kevon

    it the above code placed in your masterpage?

    /Jan

  • Kevon K. Hayes 255 posts 281 karma points
    Jan 28, 2011 @ 20:43
    Kevon K. Hayes
    0

    No it's in the UserControl... should I move it directly to the MasterPage?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 28, 2011 @ 21:25
    Jan Skovgaard
    0

    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

  • Sascha Wolter 615 posts 1101 karma points
    Jan 28, 2011 @ 22:39
    Sascha Wolter
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft