Why do some User Controls display as a class and other don't? (Master Page Goodness)

Last post 04-11-2008 10:39 AM by uwspstar. 6 replies.

Sort Posts:

  • Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-08-2008, 7:31 PM
    • Member
      7 point Member
    • JasonTrinacle
    • Member since 03-26-2008, 2:16 PM
    • Utah
    • Posts 20

    While trying to figure out how to access a user control's methods contained in a master page dynamically from a content page, I came across this (pseudo)code:

        Dim ucm As UC_MyUserControl = DirectCast(Me.Page.Master.FindControl("myUserControl"), UC_MyUserControl) 

     My problem is that only a partial list of the classes attached to my user controls display via Intellisense when I start typing "UC_" (the prefix for all my user controls)

    Can anyone explain this behavior?  If I can instantiate my user control into an object and call the methods attached to that user control (and, more importantly, pass it arguments), then I have come a long way to finishing my current project!

     

    Any help would be Greatly Appreciated!

     

    Jason 

    Jason Lindsay
    Development Lead
    STARTright LLC
  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-08-2008, 10:41 PM
    • All-Star
      98,481 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,383
    • Moderator
      TrustedFriends-MVPs

    if the user is on the page that you are accessing it from then its Type would be recognized as the control would be registered with the page.

    It looks like you're accessing a control on a MasterPage from the code-behind of a content page.  That user control is probably not registered on the content page so its Type is not recognized.  Drag/Drop the usercontrol onto the content page itself and then delete it. Then look in the markup up by the page directive and you should see that the control is now registered on your content page.  Now try casting to that Type.

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-09-2008, 10:17 AM
    • Member
      7 point Member
    • JasonTrinacle
    • Member since 03-26-2008, 2:16 PM
    • Utah
    • Posts 20

    mbanavige:

    Drag/Drop the usercontrol onto the content page itself and then delete it. Then look in the markup up by the page directive and you should see that the control is now registered on your content page.  Now try casting to that Type.

    That worked perfectly!  Now my user control class is appearing on the code-behind page and I can type to it, and call the methods attached to that user control.

    But now I am getting an "ambiguous name" error when I run the page.  Could this be because the class is already being defined on the Master Page?  Any idea how I could get around this?

    Thanks,

    Jason

    Jason Lindsay
    Development Lead
    STARTright LLC
  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-09-2008, 4:17 PM
    • Participant
      1,558 point Participant
    • brucevde
    • Member since 08-28-2007, 10:45 PM
    • British Columbia
    • Posts 233

    Try using the @Reference directive instead of @Register in the content page.

     <%@ Reference Control="~/uc_MyControl.ascx" %>

     

     

  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-10-2008, 7:01 PM
    Answer
    • All-Star
      98,481 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,383
    • Moderator
      TrustedFriends-MVPs

    JasonTrinacle:

    But now I am getting an "ambiguous name" error when I run the page.  Could this be because the class is already being defined on the Master Page? 

    Using a usercontrol on both your masterpage and a content page shouldn't be a problem.  Usually when i get an error like that it's caused by a stale temporary assembly from a prior build.  Doing a full rebuild has always cleared that type of error for me.

     

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-11-2008, 9:09 AM
    • Member
      7 point Member
    • JasonTrinacle
    • Member since 03-26-2008, 2:16 PM
    • Utah
    • Posts 20

    Thanks!  That worked.  I found a back-up copy of my user control that contained the same class name, but re-buidling the project cleared up the error altogether.

    Jason

    Jason Lindsay
    Development Lead
    STARTright LLC
  • Re: Why do some User Controls display as a class and other don't? (Master Page Goodness)

    04-11-2008, 10:39 AM
    • Member
      733 point Member
    • uwspstar
    • Member since 03-23-2008, 4:36 PM
    • Milwaukee
    • Posts 210

    mbanavige:

    if the user is on the page that you are accessing it from then its Type would be recognized as the control would be registered with the page.

    It looks like you're accessing a control on a MasterPage from the code-behind of a content page.  That user control is probably not registered on the content page so its Type is not recognized.  Drag/Drop the usercontrol onto the content page itself and then delete it. Then look in the markup up by the page directive and you should see that the control is now registered on your content page.  Now try casting to that Type.

    mbanavige 's answere also solve my problem too

    founder of AskBargains.com



    If you mark as "Answer"other people can use this answer as a reference
Page 1 of 1 (7 items)