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
Do I have some syntax error above?
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.