I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page.
When I try to load the CSS & JS files using the code behind of the content page, my buttons aren't rendered and Im not sure why?
Here is the code for my content page - Properties.aspx:-
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="C#" AutoEventWireup="true" Title="Properties" CodeFile="Properties.aspx.cs" Inherits="Properties" MasterPageFile="~/MasterPage.master"%>
- <asp:Content ID="_propertiesContent" ContentPlaceHolderID="_mainContentHolder" runat="Server">
- <asp:Label ID="_test" Text="This is the main content panel holder" runat="server" />
- <br />
- </asp:Content>
- <asp:Content ID="_buttonContent" ContentPlaceHolderID="_buttonContentHolder" runat="server" >
- <asp:Button ID="Button1" runat="server" Text="Save" CssClass="button" />
- <asp:Button ID="Button2" runat="server" Text="Undo" CssClass="button" />
- <br />
- </asp:Content>
- <asp:Content ID="_validationContent" ContentPlaceHolderID="_validationContentHolder" runat="server">
- <asp:ValidationSummary ID="validationSummary" ValidationGroup="ValidationGroup" runat="Server" />
- </asp:Content>
Expand|Select|Wrap|Line Numbers
- using ASP;
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class Properties : Page
- {
- private string _pageName;
- protected void Page_Load(object sender, EventArgs e)
- {
- _pageName = Page.GetType().Name.Substring(0, Page.GetType().Name.IndexOf("_"));
- if (!IsPostBack)
- {
- LoadStyleSheets();
- LoadJavascriptFile();
- }
- }
- private void LoadStyleSheets()
- {
- HtmlLink link = new HtmlLink();
- link.Href = string.Format("~/{0}.css", _pageName);
- link.Attributes["text"] = "text/css";
- link.Attributes["rel"] = "stylesheet";
- this.Header.Controls.Add(link);
- }
- private void LoadJavascriptFile()
- {
- HtmlGenericControl javaScriptLink = new HtmlGenericControl();
- javaScriptLink.TagName = "script";
- javaScriptLink.Attributes.Add("type", "javascript");
- javaScriptLink.Attributes.Add("src", string.Format("JS/{0}.js", _pageName));
- }
- }
My Master Page code is:-
Expand|Select|Wrap|Line Numbers
- <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" Debug="true"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head id="Head1" runat="server">
- <title>Master Page</title>
- </head>
- <body>
- <form id="MainForm" runat="server">
- <!-- This bit in here needs to be configurable per page, main content section -->
- <asp:ContentPlaceHolder ID="_mainContentHolder" runat="server" />
- <!-- This bit in here needs to be configurable per page, button section -->
- <asp:ContentPlaceHolder ID="_buttonContentHolder" runat="server" />
- <!-- This bit is for the validation summary for each page -->
- <asp:ContentPlaceHolder id="_validationContentHolder" runat="server" />
- </form>
- </body>
- </html>
If I comment out the methods to Load CSS file & Load JS files in my properties page - then my label text & my buttons are rendered, but if I leave these methods in, then only my Label text renders - Any ideas why?
Many thanks
Janet