Tech Off Thread

16 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Sandbox Request - C# Master Pages Sample

Back to Forum: Tech Off
  • User profile image
    phreaks

    I've been trying to get a grasp around Master Pages.
    I haven't done a whole lot of web work in the past few years, and really don't have any need for it in my current professional capacity, but I would still like to understand it.

    I have read a few articles and was wondering if anyone could post a simple Master Pages sample for me to digest (preferably in C# or J#).

    Nothing over the top, I am just trying (at this point) to understand how the ContentPlaceholders interact with your pages and how and when to use them.

    TIA

  • User profile image
    Lee_Dale

    Just think of the ContentPlaceHolder as a page within a page?

    like your including ASP code from another page into your master page whetehr the placeholde is, bit like an include file.

    Ill post an example later if i get time.

  • User profile image
    stevef100
  • User profile image
    phreaks

    stevef100 wrote:


    OK, thanks. So perhaps I am misunderstanding Masterpages.

    Can you not use them to for Controls that require State, for example say a navigation control?

  • User profile image
    mig

    I believe I saw one or two screencasts right here on C9 that deal with master pages... hope it helps.

  • User profile image
    littleguru

    phreaks wrote:
    
    stevef100 wrote: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/masterpages/default.aspx#content


    OK, thanks. So perhaps I am misunderstanding Masterpages.

    Can you not use them to for Controls that require State, for example say a navigation control?



    You should see the master page as a template for the web site. It holds all the page stuff that is on all pages the same. The contentplaceholder holds the content for a certain page.

    Example
    You have a website with a navigation (on the left) and a header (top). This part is always the same. Right of the navigation you have the content.

    You create a new masterpage and put the top (header) and left (navigation/menu) part and a contentplaceholder in the masterpage.
     
    Now you right click on the masterpage file (in Visual Studio) and "Create Content Page". Visual Studio creates a new .aspx file that holds a reference to the master page and the content place holder. There you put the content of the page.

    You can access the master page from the code behind, by doing: this.Master.something.

    You could for example add a property/method to your master page (let's say the master page is named MyMaster).

    You can access that property by using:

    string foo = ((MyMaster)this.Master).MyProperty;
    ((MyMaster)this.Master).SetTitle(...);

    That allows you to edit the content of the master page from the content page...

  • User profile image
    littleguru

    I put a sample project online: http://www.littleguru.net/Misc/Website1.zip

  • User profile image
    phreaks

    littleguru wrote:
    I put a sample project online: http://www.littleguru.net/Misc/Website1.zip


    Excellent, thanks.

  • User profile image
    phreaks

    One more thing.

    Once I place a Contentholder on a Master page in the IDE, how do I size it and move it around?

    When I mouse over some areas, I do get a resizable cursor, indicating I can resize it, but any attempts to do so result in nothing.

    Same thing occurs when I try to move it...Expressionless

  • User profile image
    blowdart

    phreaks wrote:
    

    One more thing.

    Once I place a Contentholder on a Master page in the IDE, how do I size it and move it around?

    When I mouse over some areas, I do get a resizable cursor, indicating I can resize it, but any attempts to do so result in nothing.

    Same thing occurs when I try to move it...Expressionless



    Size it? It's not a sizeable thing; it isn't like a panel in Winforms. It'll resize to whatever you want. If you really want sizing or absolute positioning it's time to break out CSS, and wrap the placeholder in a div tag.

  • User profile image
    phreaks

    blowdart wrote:
    
    phreaks wrote: 

    One more thing.

    Once I place a Contentholder on a Master page in the IDE, how do I size it and move it around?

    When I mouse over some areas, I do get a resizable cursor, indicating I can resize it, but any attempts to do so result in nothing.

    Same thing occurs when I try to move it...Expressionless



    Size it? It's not a sizeable thing; it isn't like a panel in Winforms. It'll resize to whatever you want. If you really want sizing or absolute positioning it's time to break out CSS, and wrap the placeholder in a div tag.


    ah, I see thanks for the clarification

  • User profile image
    littleguru

    You could do some javascript magic here, to have it sizable and movable. You could put the contentplaceholder in a div (in the masterpage) and apply javascript on that div... It's custom code that you would need to develop!

  • User profile image
    phreaks

    littleguru wrote:
    You could do some javascript magic here, to have it sizable and movable. You could put the contentplaceholder in a div (in the masterpage) and apply javascript on that div... It's custom code that you would need to develop!


    Yeah, I guess my confusion stems from how it appears in the designer. When you drop one on a page, it is freakin huge.

    I am figuring I will define my page layout structure as a table in a Master Page and then place my Content PlaceHolders in the appropriatte columns.

    That should work, aye?

  • User profile image
    littleguru

    phreaks wrote:
    
    littleguru wrote: You could do some javascript magic here, to have it sizable and movable. You could put the contentplaceholder in a div (in the masterpage) and apply javascript on that div... It's custom code that you would need to develop!


    Yeah, I guess my confusion stems from how it appears in the designer. When you drop one on a page, it is freakin huge.

    I am figuring I will define my page layout structure as a table in a Master Page and then place my Content PlaceHolders in the appropriatte columns.

    That should work, aye?



    Yep. Although you should use DIVs instead of TABLEs Tongue Out

  • User profile image
    phreaks

    littleguru wrote:
    
    phreaks wrote: 
    littleguru wrote: You could do some javascript magic here, to have it sizable and movable. You could put the contentplaceholder in a div (in the masterpage) and apply javascript on that div... It's custom code that you would need to develop!


    Yeah, I guess my confusion stems from how it appears in the designer. When you drop one on a page, it is freakin huge.

    I am figuring I will define my page layout structure as a table in a Master Page and then place my Content PlaceHolders in the appropriatte columns.

    That should work, aye?



    Yep. Although you should use DIVs instead of TABLEs

    Yeah, I know and I'll get there eventually. Like I said, I haven't done any real web work in sometime (before CSS positioning), so for now I will use tables because I know how, later I will refactor to use CSS positioning.

  • User profile image
    blowdart

    phreaks wrote:
    
    Yeah, I know and I'll get there eventually. Like I said, I haven't done any real web work in sometime (before CSS positioning), so for now I will use tables because I know how, later I will refactor to use CSS positioning.


    Just think upon it as the HTML a page spits out instering itself into the content holders on the master page.

    So yes, you can certainly use tables or CSS for layouts; but that also explains why it's not a sizeable element; it's not really an element at all, but instructions showing where the HTML will be placed.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.