ContentPlaceHolder not working - asp.net

I need your help:
Asp ContentPlaceHolder is not working.
"blao balo bla balll" is not shown.
in Html code:
<!-- Insert default "slide" markup here -->
This is my Code - HomePage.master:
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<asp:ContentPlaceHolder Id="slide" runat="server">
<!-- Insert default "slide" markup here -->
</asp:ContentPlaceHolder>
</asp:Content>
slide.master:
<%# Master Language="C#" MasterPageFile="~/masterpages/HomePage.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderId="slide" runat="server">
blao balo bla balll
</asp:Content>

Since the slide template uses the HomePage template as master page and replaces the content of a ContentPlaceHolder defined in the HomePage template, you should make sure to use the slide template whenever you want to display non default slide markup.
When using the HomePage template, as expected the default markup as defined in the HomePage template gets displayed.

Related

Using server tags inside of a local ASP.NET page contained in an iframe

I have a class that modifies the path of a resource (e.g., a stylesheet) based on that file's last modified time. This is in order to prevent caching of stale resources.
The class works on all "normal" pages, but I can't get it to work in a local ASP.NET page that's rendered inside of an iframe. The class is located in ~/App_Code:
fingerprint.aspx.cs
public class Fingerprint {
public static string Tag(string rootRelativePath) {
if (HttpRuntime.Cache[rootRelativePath] == null) {
string absolute = HostingEnvironment.MapPath(rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
int index = rootRelativePath.LastIndexOf('/');
string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
}
And in under most circumstances, it works successfully if called as follows:
somepage.aspx
<%# Page Language="C#" AutoEventWireup="true" Inherits="MainSite" CodeFile="somepage.aspx.cs" %>
<html>
<head runat="server">
<title>Title</title>
<link rel="stylesheet" href="<%# Fingerprint.Tag("/path/to/resource.css") %>">
<!-- other markup -->
</head>
<body>
<!-- other markup -->
</body>
</html>
But if I have an ASP.NET page that loads another ASP.NET page inside an iframe, it doesn't seem to get called. Example:
parent.aspx
<%# Page Language="C#" AutoEventWireup="true" Inherits="MainSite" CodeFile="parent.aspx.cs" %>
<asp:Panel ID="Container" runat="server">
<iframe id="testFrame" src="child.aspx"></iframe>
</asp:Panel>
child.aspx
<%# Page Language="C#" AutoEventWireup="true" Inherits="MainSite" CodeFile="child.aspx.cs" %>
<html>
<head runat="server">
<title>Title</title>
<link rel="stylesheet" href="<%# Fingerprint.Tag("/path/to/resource.css") %>">
<!-- other markup -->
</head>
<body>
<!-- other markup -->
</body>
</html>
I don't get any errors, but Fingerprint.Tag doesn't seem to even be getting called. I just get an empty string in the href portion of the <link> tag where the path to my stylesheet would normally be.
Is there a trick to getting server tags to work inside of local ASP.NET pages contained in iframes? I'm using ASP.NET WebForms (no other choice, client requirement).
What about changing <%# Fingerprint.Tag("/path/to/resource.css") %> to <%=Fingerprint.Tag("/path/to/resource.css") %>? Changing # to =.
As far as I know, <%# ... %> is more like a data binding syntax.

Two instances of the same usercontrol in an asp.net page

In my webpage I use two user controls:
ucControl1 and ucControl2. The ucControl1 control also contains an instance of the ucControl2 control inside it.
When you run the application and go to the page in question, it appears that only the instance that is inside the ucControl1 is working correctly. When trying to execute the functionality of the ucControl2 that is directly on the page, it correctly executes the backend code, opens the modal correctly but does not show the results on the screen.
What could be happening?
The page is like this
<%# Page Language="C#" AutoEventWireup="true" CodeFile="PageSample.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="PageSample" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<%# Register Src="~/Controls/ucControl1.ascx" TagPrefix="uc1" TagName="ucControl1" %>
<asp:Content runat="server" ContentPlaceHolder ID="cpSampleID">
<div>
<uc1:ucControl2 runat="server" ID="uc2" />
</div>
<uc1:ucControl1 runat="server" ID="uc1" />
</asp:Content>
And the usercontrol1
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl1.ascx.cs" Inherits="ucControl1" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc1" TagName="ucControl2" %>
<%-- Something Something Something --%>
<uc1:ucControl2 runat="server" ID="ucControl2" />
I've found a solution. The modal is opened by javascript.
ucControl2
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl2.ascx.cs" Inherits="ucControl2" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<div id="modal">
<!-- Some Textboxes -->
</div>
Method to open the modal
public void OpenModal()
{
string id = "modal";
string js = $#"
$(document).ready(function() {{
if ($('.modal.in').length > 0) {{
$('.modal').on('hidden', function() {{
$('.modal').off('hidden');
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}});
$('.modal').modal('hide');
}} else {{
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}}
}});";
ScriptManager.RegisterStartupScript(this, this.GetType(), id, js, true);
}
So when the control is called, the javascript does not know which of the controls should open, and in this case it is opening the first control that is on the page.
To solve it I've changed the div through an asp panel, in this way asp generates a different client ID for each control and the controls are displayed correctly.

MVC Child Master page with Razor

I have an old MVC2 project that I gradulately convert to MVC 5, with Razor.
As the razor views with ASP Master Pages is not possible, I decided to duplicate the Site.Master into _Layout.cshtml.
Everything is OK But there is a problem, however.
I have an other Master page, TwoColumnsLayout.Master, a kind of "child" master page, that begins like this:
<%# Master MasterPageFile="~/Views/Shared/Site.Master" Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<asp:Content ContentPlaceHolderID="MetaContent" runat="server">
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<div class="breadcrumbs">
...
How is possible to convert and use this one with the Razor engine?
utilize #{ Layout = ""; } feature.
For Example:
~/Views/Shared/_LayoutMain.cshtml:
<html>
<head>
<link href="..." rel="stylesheet" type="text/css" />
</head>
<body>
<!-- header markup -->
#RenderBody()
<!-- footer markup -->
</body>
</html>
~/Views/Shared/_LayoutChild.cshtml:
#{
Layout = "~/Views/Shared/_LayoutMain.cshtml";
}
<!-- Child Layout content -->
<div>
#RenderBody()
</div>
~/Views/MyPage/_SomeViewPage.cshtml:
#{
Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
<div>
#RenderBody()
</div>
You just need to use nested layout templates instead.
Create another layout _TwoColumnsLayout.cshtml with the following:
#{
Layout = "~/Shared/_Layout.cshtml";
}
//Nested specific markup ...
#RenderBody()
Then in your view specify your new nested template as follows:
#{
Layout = "~/Shared/_TwoColumnsLayout.cshtml.cshtml";
}

ASP.NET ContentPage with Form Controls

I created a content page that references a master page. In the content page I have a form and some form controls with a submit button. When I hit submit though the parameters are not detected on page load in the content page. On top of that the name of the parameters are all messed up.
What is the correct way of adding form controls to the content page and then using Request.QueryString[ID]?
I just realized that Microsoft throws all kinds of extra crap at you when you use master pages. It is absolutely ridiculous, is there a way for me not to go down this route of using all kinds of silly casting and inefficient overhead:
http://www.asp.net/web-forms/tutorials/master-pages/control-id-naming-in-content-pages-cs
My code (MASTER PAGE):
<%# Master Language="C#" AutoEventWireup="true" ClientIDMode="Static" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="Head" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
</body>
</html>
My code (Content Page):
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<label for="iSiteId">Site Id(s)</label>
<asp:TextBox ID="iSiteId" runat="server"></asp:TextBox>
<label for="iVersion">Version(s)</label>
<asp:TextBox ID="iVersion" runat="server"></asp:TextBox>
</asp:Content>
My Code (Content Page but the Code behind)
_siteId = Request.QueryString["iSiteId"];
_categoryId = Request.QueryString["iCategoryId"];
_version = Request.QueryString["iVersion"];
Try these instead:
siteId = iSiteId.Text;
_categoryId = iCategoryId.Text;
_version = iVersion.Text;

Filling in parent master page from child

I'd like to have a page that uses a child master page, fill in a content placeholder of the parent, but I cannot get it to work. Whenever I try I get the error "Cannot find ContentPlaceHolder 'customHead' in the master page '/templates/info.master', verify content control's ContentPlaceHolderID attribute in the content page."
I have a master page (/templates/main.master) defined like this:
<%# Master Language="C#" %>
<head runat="server">
<title>foo</title>
<asp:contentplaceholder runat="server" id="customHead" />
</head>
<body>
<div id="content">
<asp:contentplaceholder runat="server" id="masterContent" />
</div>
Then I have a child master (/templates/info.master) defined like this:
<%# Master Language="C#" MasterPageFile="/templates/main.master" %>
<asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
<div id="info-container">
<div id="info-content">
<asp:contentplaceholder runat="server" id="infoContent"/>
</div>
</div>
</asp:content>
And finally my page defined like this:
<%# Page Language="C#" MasterPageFile="/templates/info.master" %>
<asp:Content ID="head" ContentPlaceHolderID="customHead" runat="server">
<!-- Custom header area -->
<link rel="stylesheet" type="text/css" href="foo.css"/>
</asp:Content>
<asp:Content ID="content" ContentPlaceHolderID="childContent" runat="server">
This is my child content
</asp:Content>
You didn't define a "customeHead" in your child master page. If you want to expose the root master pages content area, you'll need to expose it in the child master page.
<%# Master Language="C#" MasterPageFile="/templates/main.master" %>
<asp:contentplaceholder runat="server" id="customHead" />
<asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
<div id="info-container">
<div id="info-content">
<asp:contentplaceholder runat="server" id="infoContent"/>
</div>
</div>
</asp:content>
Are you setting it using this.Page.Master ?

Resources