Can a UserControl use a Masterpage? Why not?

Last post 05-25-2006 3:22 PM by MorningZ. 2 replies.

Sort Posts:

  • Can a UserControl use a Masterpage? Why not?

    05-25-2006, 2:50 PM
    • Member
      731 point Member
    • Plucky
    • Member since 07-09-2002, 8:16 PM
    • Alaska
    • Posts 156

       I need to create a control that puts a box around any content i desire.  I've done this with 2 usercontrols in the past (1 to open a table, 2nd to close the table around the content). 

    I thought masterpages would be a better solution...but i can't use masterpagefile=Box.master within a control directive...

    This: <%@ Control MasterPageFile="~/MasterPages/Box1.master" %>
    produces: Error parsing attribute 'masterpagefile': Type 'System.Web.UI.UserControl' does not have a public property named 'masterpagefile'.

    Any ideas on what approach i should be taking?  Or if there is another way to impliment masterpages in a usercontrol?

      
  • Re: Can a UserControl use a Masterpage? Why not?

    05-25-2006, 3:10 PM
    • All-Star
      27,998 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,647

    Hey,

    No, masterpages are for the page only; user controls compile as part of the page as a control, and that is by design.  Why not create a custom panel control, that renders whatever around the content in the panel?

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Can a UserControl use a Masterpage? Why not?

    05-25-2006, 3:22 PM
    • Star
      8,834 point Star
    • MorningZ
    • Member since 07-22-2002, 10:39 AM
    • Fort Lauderdale, FL
    • Posts 1,815

    To back up what's posted right above this one, maybe this post will help

    http://forums.asp.net/thread/1274884.aspx

    This is the perfect time for making your own WebControl (not Usercontrol)

    "If you make it idiot proof, they'll build a better idiot"
Page 1 of 1 (3 items)