views:

38

answers:

3

I have multiple pages that have this pattern.

    <iframe frameborder ="0" src="[someURL]" width="100%" height="900">
    </iframe>

I want to factor out everything but the URL into a master page so i tried this:

Master Page:

    <iframe frameborder ="0" src=<asp:ContentPlaceHolder ID="Url" runat="server" /> width="100%" height="900">
    </iframe>

Child Page:

 <asp:Content ID="Content2" ContentPlaceHolderID="Url" runat="server">
     "http://myURL"
</asp:Content>

but it doesn't seem to work. I get this error:

Cannot find ContentPlaceHolder 'Url' in the master page

Any suggestions if i have some syntax error above

+1  A: 

It sounds like you want to re-use a snippet such that the View can dictate what the URL of the iFrame is, and the Master holds the actual iFrame.

Consider this potential solution:

The URL is put into ViewData from the Controller. Convention is that Views are dumb. So you could put this iFrame into your Master:

<iframe frameborder ="0" src="<%=ViewData["yourURL"] %>" width="100%" height="900"></iframe>

This requires that your Controller knows, or can find, the URL for the View that's being requested. You could hard-code this right in your Controller method, or pull it from the web.config.

p.campbell
@p.campbell - actually just stuck the URL in my viewmodel and now only have a single view.
ooo
+1  A: 

Hey,

I don't think that will work very well... Could you pass along a URL into ViewData within the controller instead, and inject that? Or create some component that pulls the correct value from a backend source based on the current URL, or something?

HTH.

Brian
A: 

There are better ways of getting your source into the element but if you need to stick with the implementation you are using you can do this...

<iframe frameborder ="0" src="<asp:ContentPlaceHolder ID="UrlContent" runat="server" />" width="100%" height="900">
</iframe>

Notice that I have quotes before and after the content placeholder. Then you can just have content that looks like this...

<asp:Content ID="Content3" ContentPlaceHolderID="UrlContent" runat="server">
    http://www.stackoverflow.com
</asp:Content>

Intelisense will not like what you are trying to do but it will work.

Steve Hook