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
-
-
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. -
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?
-
I believe I saw one or two screencasts right here on C9 that deal with master pages... hope it helps.
-
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... -
I put a sample project online: http://www.littleguru.net/Misc/Website1.zip
-
littleguru wrote:I put a sample project online: http://www.littleguru.net/Misc/Website1.zip
Excellent, thanks. -
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...

-
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...

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.
-
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...

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 -
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!
-
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?
-
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
-
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. -
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.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.