G
Guest
I am working on developing a generic Web framework using Master Pages in
ASP.NET 2.0. What I have done is created a PageRenderer class which has a
public method which will retrieve the path of the content I want to execute
based on the name of the asp:Content control. As shown in the code snippet
below, to get the content I want to display, I call the GetContentPagePath
public method in PageRenderer passing a string duplicating the value in the
ContentPlaceHolderID, i.e.:
Server.Execute(PageRenderer.GetContentPagePath("ContentTopMenu"));
However, I would prefer not to use a hard coded value, but rather
programmatically determine ContentPlaceHolderID value for the current
asp:Content control and pass that as a parameter. By doing this, I can use
same method call into each asp:Content control in the .master file. However,
my initial research didn't yield a way to programmatically at runtime
determine the ContentPaceHolderID value of the current actively asp:Content
control. The Master object looked promising, however, as far as I could
tell, there wasn't anything to indicate which was the currently actively
control.
In playing around in the debugger, I saw that in the Locals window, there
was parameterContainer object available and it had a property called ID which
has the value that I need. However, I can't find this object documented and
I am hesitant to use even though it provides me what I need. Does anyone
know of a way to determine at runtime the ContentPlaceHolderID value of the
asp:Content control that is currently running the ASPX code?
Thanks.
<%@ Page Language="C#"
MasterPageFile="~/_framework/masterlayouts/masterlayout1/masterlayout1.master"
AutoEventWireup="true" CodeFile="masterlayout1_content.aspx.cs"
Inherits="_framework_masterlayouts_masterlayout1_content" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentTopMenu"
Runat="Server">
<%
Server.Execute(PageRenderer.GetContentPagePath("ContentTopMenu"));
OR
Server.Execute(PageRenderer.GetContentPagePath(parameterContainer.ID));
%>
</asp:Content>
ASP.NET 2.0. What I have done is created a PageRenderer class which has a
public method which will retrieve the path of the content I want to execute
based on the name of the asp:Content control. As shown in the code snippet
below, to get the content I want to display, I call the GetContentPagePath
public method in PageRenderer passing a string duplicating the value in the
ContentPlaceHolderID, i.e.:
Server.Execute(PageRenderer.GetContentPagePath("ContentTopMenu"));
However, I would prefer not to use a hard coded value, but rather
programmatically determine ContentPlaceHolderID value for the current
asp:Content control and pass that as a parameter. By doing this, I can use
same method call into each asp:Content control in the .master file. However,
my initial research didn't yield a way to programmatically at runtime
determine the ContentPaceHolderID value of the current actively asp:Content
control. The Master object looked promising, however, as far as I could
tell, there wasn't anything to indicate which was the currently actively
control.
In playing around in the debugger, I saw that in the Locals window, there
was parameterContainer object available and it had a property called ID which
has the value that I need. However, I can't find this object documented and
I am hesitant to use even though it provides me what I need. Does anyone
know of a way to determine at runtime the ContentPlaceHolderID value of the
asp:Content control that is currently running the ASPX code?
Thanks.
<%@ Page Language="C#"
MasterPageFile="~/_framework/masterlayouts/masterlayout1/masterlayout1.master"
AutoEventWireup="true" CodeFile="masterlayout1_content.aspx.cs"
Inherits="_framework_masterlayouts_masterlayout1_content" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentTopMenu"
Runat="Server">
<%
Server.Execute(PageRenderer.GetContentPagePath("ContentTopMenu"));
OR
Server.Execute(PageRenderer.GetContentPagePath(parameterContainer.ID));
%>
</asp:Content>