[RESOLVED]Confused with Nested Templates

So I am confused about creating nested templates, I need help!

OK so here is my site structed

Wrapper

Header

Container

left-column

Page_Content

Right_column

footer

(left-column, page-content, right column are inside container. Add everthing is inside wrapper)

OK so whats bugging me is that, left-column will have links like:

HTML
CSS
ASP

these will display on everypage unless I change it. So If someone clicks HTML,they will be redirected to HTML.cshtml. Now for the HTML.cshtml it will have its own template _HTML (_HTML, will be running from the MainLayout) However for the _HTML page, I do
not want the links:

HTML
CSS
ASP

I want links to do with HTML, e.g. Paragraphs etc. How can I change this, but keep the site layout same?

if you don’t undertstand me, then this should help:

http://www.w3schools.com/

When you click on HTML, watch how the links on the left change to all HTML topics, but the design is still the same.

to do that you have two options:

first, you can create a user control that accepts a value that identifies what links it should be showing. this value can be a data table that you can select from or just a service. pretty much everything that can identify your resources to show as links
in <asp:BulletedList DisplayMode="HyperLink">

two, you can create multiple user controls. each contain many links and then load the appropriate one dynamically by calling Page.LoadControl(@"myUC.ascx.cs") or Page.LoadControl(@"myUC.ascx.vb")

Lol I have done it in a much easier way. Tell me if this method is good:

I made the main template, and I put no content in the left column except

@RenderSection("left")

Then I made a new template, which runs of the main template, then in the new template I  put:

@section left{

HTML
CSS
VB

}

then for the default page, I linked that to the new template I made. Then for the HTML pages, I made a new template (_HTML) made the @section left{}  different and it worked! Rendered different content.

If you want to use the same layout page, but have content that might change, or not appear at all in that layout, sections is a good approach. User Controls as proposed by hj belong to web forms. They are not relevant to ASP.NET Web Pages.

Mikesdotnetting

If you want to use the same layout page, but have content that might change, or not appear at all in that layout, sections is a good approach. User Controls as proposed by hj belong to web forms. They are not relevant to ASP.NET Web Pages.

lol it’s Mike Brind! I was actually reading your book, Beginning ASP.NET with Webmatrix, until I reached a dead end, Good Book though! learnt a lot from reading the first 3-4 chapters. 

Leave a Reply