I have very little experience with ASP or .NET but have a need to make some content and style edits to one of such sites. The problem is that I am having a hard time finding the section which I need to edit.
In the main file called default.aspx, there is code like this:
<%# Page Title="" Language="VB" MasterPageFile="~/Company_New_NoMenus.master" CodeFile="Default.aspx.vb" Inherits="_Default" AutoEventWireup="false" %>
<%# Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
content here
The content which needs to be edited is located inside the ContentPlaceHolderID="HeadContent". I cannot find where it is populated. I tried searching the directory of the site to no avail.
If you use Windows Server, IIS and ASP, I would love some ideas about where I could look for it. Could it be set in the environment or be done in some other strange way? How would you look for it?
Any help is appreciated!
Related
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="XEx02Quotation._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<html>
<head runat="server">
<title></title>
</head>
<body>
</body>
</html>
</asp:Content>
I am confuse about why Visual Studio 2017 doesn't let me add HTML elements into the Default.aspx, but what I do know is that under the Solution Explorer, I see master page and apparently they are bind to the content page (which is the Default.aspx). Also, I put a copy of my screenshot problems.
So my question is do I start putting content (HTML elements) inside of that master page first!
Aside from what I have mentioned above, I also notice that when I try to put basic HTML elements into the #page directive (Default.aspx file), it says "“Content is not supported outside of 'script' or 'asp:Content' Regions” ".
The only reason I know of these terms is because I research this problem. Here are the article that I have researched. "Content Not Supposed to Be Outside 'Script' or 'asp:Content' Regions" AND https://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx
Here are the screenshot problems:
You can put HTML elements like this:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <div>Test</div> </asp:Content>.
If you want to edit the and others and things like that, you can make that inside the Site.Master.
But if you want to add other HTML pages you need to make new HTML page and add that inside the page you want(Maybe Default.aspx) , like this Stack answer.
I'm getting this output:
even though my page contains MasterPageFile="~/Site1.Master"
Here's my page's source code:
<%# Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Projekt.NET.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<title>gowno</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
hahahahahahaa
</asp:Content>
as Self-Anserwed by 'ProfK'
<%# Page Language="C#" 'directive is missing the word Page'
Master Page Error on New MVC Project
i thought this was a simple issue until i started searching for answers and realised it's so simple i'm the only one who has it
my user control isnt displaying anything. what am i doing wrong? (besides letting this be my life...)
control:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ctrl.ascx.cs" Inherits="proj.UserControls.ctrl" %>
asdjkldasfjasdfljdfasjklasdfjkl
use:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="page.aspx.cs" Inherits="proj.Admin.page" %>
<%# Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<cc1:ctrl ID="test" runat="server" />
</asp:Content>
Change:-
<%# Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>
To
<%# Register TagPrefix="cc1" TagName="ctrl" Src="/path/to/ctrl.ascx" %>
You're missing TagName, which represents the text following the colon in the control declaration. You're also not telling the engine where to find the source file ( Src attribute ). Change /path/to to represent the path from root to your control.
IF you have created custom control then you should add reference of the dll of your custom control ( from choose items from ToolBox of Visual Studio). and then Use the following tag in the page :
<%# Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>
If you created User Control then add the following line in your page:
<%# Register src="~/UserControls/ctrl.ascx" TagName="ctrl" tagprefix="cc1" %>
instead of
<%# Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>
use
<%# Register src="~/UserControls/ctrl.ascx" TagName="ctrl" tagprefix="cc1" %>
Make sure you haven't set visible="false" on a panel or div containing your control.
That would've saved me a good hour.
I had to add a new user control to an existing project that already contained a lot of them, and wondered why mine was not rendering. Turns out you can also specify this in Web.config, under configuration, system.web, pages, like this:
<controls>
<add tagPrefix="cc1" tagName="ctrl" src="~/UserControls/ctrl.ascx" />
...which will register the control for the whole project, so you don't have to specify this on every page. Useful for controls that are heavily reused.
I have a feeling I'm missing one small thing. I have very simple page, created from the ASP.NET templates in VS2010. My Default.aspx consists of simply the following code. The Site.Master page is doing what it's supposed to.
<%#Page
Title="Home Page"
Language="C#"
MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="UserControlTest._Default" %>
<%#Register
TagPrefix="tsi"
Namespace="UserControlTest.Controls"
Assembly="UserControlTest" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<!-- HERE BE DRAGONS -->
<tsi:BigHelloBanner runat="server" />
<tsi:SmallHelloBanner runat="server" />
</asp:Content>
BigHelloBanner contains this:
<%#Control
Language="C#"
AutoEventWireup="true"
Visible="true"
CodeBehind="BigHelloBanner.ascx.cs"
Inherits="UserControlTest.Controls.BigHelloBanner" %>
<h1>HI!</h1>
Both the codebehind files in both objects are empty, and inherit from UserControl. The behavior is the same inheriting from Control. When I view-source on the rendered output, nothing from the HelloBanners is output, except some newlines. The HERE BE DRAGONS comment is visible, which indicates to me that the master page and all that works fine. I am expecting to see the <h1>HI!</h1> markup in the output as well. What am I missing? This seems really basic.
It looks like that you're referring to the empty code-behind class instead of the ASCX file with the output. Use the src attribute in your #Register directive:
<%#Register
TagPrefix="tsi"
TagName="BigHelloBanner"
Src="BigHelloBanner.ascx" %>
I can't see the src attribute here where is your control held ?
<%#Register
TagPrefix="tsi"
Namespace="UserControlTest.Controls"
Assembly="UserControlTest"
src="?" %>
Since BigHelloBanner is a web user control, you should try registering it like this:
<%#Register TagPrefix="tsi" TagName="BigHelloBanner" Src="~/pathToUserControls/BigHelloBanner.ascx" %>
Don't you still need to give an ID to each control instance?
I'm very new to ASP.NET, help me please understand MasterPages conception more.
I have Site.master with common header data (css, meta, etc), center form (blank) and footer (copyright info, contact us link, etc).
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="_SiteMaster" %>
<!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="tagHead" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<form id="frmMaster" runat="server">
<div>
<asp:ContentPlaceHolder ID="holderForm" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="holderFooter" runat="server">Some footer here</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
and I want to use second master page for a project into sub directory, which would contains SQL query on Page_Load for logging (it isn't necessary for whole site).
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Project.master.cs" Inherits="_ProjectMaster" MasterPageFile="~/Site.master" %>
<asp:Content ContentPlaceHolderID="holderForm" runat="server">
<asp:ContentPlaceHolder ID="holderForm" runat="server" EnableViewState="true"></asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ContentPlaceHolderID="holderFooter" runat="server">
<asp:ContentPlaceHolder ID="holderFooter" runat="server" EnableViewState="true"></asp:ContentPlaceHolder>
</asp:Content>
But I have a problem: footer isn't displayed.
Where is my mistake? Am I right to use second master page as super class for logging?
Project page looks like this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/Project.master" %>
<asp:Content ContentPlaceHolderID="holderForm" runat="server">
<p>Hello World!</p>
</asp:Content>
<asp:Content ContentPlaceHolderID="holderFooter" runat="Server">
Some footer content
</asp:Content>
I've been working with nested master pages and have run in to something similar. From what I see where you have "Some footer here" in the Site.Master is where the problem lies and I've had similar problems with having content with-in a contentplaceholder tag. if you try this instead
<asp:ContentPlaceHolder ID="holderFooter" runat="server"/>Some footer here
Then you should be able to see the footer content.
I'm not sure I'd use master pages for this. If it's really just going to do logging, I'd implement IHttpModule, register it in web.config, and then check whether or not to log based on the path of the request. I think of master pages as being about content rather than other processing such as logging.
See the IHttpModule walkthrough on MSDN for an example - in your BeginRequest handler, you'd probably check the request path and log appropriately if it matched.
Apologies if I misunderstood what you're trying to do though.
You should leave your ContentPlaceHolder empty, for it gets substituted by the content of the Content in your actual Page...
When you move the "Some footer here" text to your Content, you will see your lines of text :)
HTH
This link gives a simple explanation on Master pages,
http://waxtadpole.wordpress.com/2009/01/16/master-page-content-not-visible-visual-studio-2008/
The question are you right to use child Master pages in this instance - I would say master pages should be helping you solve issues around building a consistent layout, not for whether or not logging should occur.
The problem is, when the text elements placed inside Default.aspx are put in their relative Content Placeholders, they are written on the placeholders of your Site.master page and not those of Project.master (which have the same names).
You should resolve the naming conflict, by assigning different ContentPlaceHolderIDs to the the placeholders in Project.master (this means you'll also have to change the references in Default.aspx).
This would be your Project.master file:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Project.master.cs" Inherits="_ProjectMaster" MasterPageFile="~/Site.master" %>
<asp:Content ContentPlaceHolderID="holderForm" runat="server">
<!-- whatever... -->
<asp:ContentPlaceHolder ID="holderFormInternal" runat="server" EnableViewState="true"></asp:ContentPlaceHolder>
<!-- ... -->
</asp:Content>
<asp:Content ContentPlaceHolderID="holderFooter" runat="server">
<asp:ContentPlaceHolder ID="holderFooterInternal" runat="server" EnableViewState="true"></asp:ContentPlaceHolder>
</asp:Content>
And thus, your .aspx pages that use the Project master page instead of the global Page.master must be changed to:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/Project.master" %>
<asp:Content ContentPlaceHolderID="holderFormInternal" runat="server">
<p>Hello World!</p>
</asp:Content>
<asp:Content ContentPlaceHolderID="holderFooterInternal" runat="Server">
</asp:Content>
If the only reason is to implement loggin why would you mess around with masterpages?
If the logging isent supposed to display any text!?
You either do as Skeet proposed with an IHTTP handler.. Or lazier one would be do have a class that derives from webpage and implement logging in that class and make your pages that need logging dervice from that..
ex:
public class LoggingPage : : System.Web.UI.Page
{
public override void OnLoad()
{
// Do logging
}
}
partial class OneOfTheWebPages : LoggingPage
{
public void onLoad()
{
base.onLoad();
}
}
I may be misunderstanding your problem - but from the code you've posted, there isn't anything in the footer.
In your Project page, the <asp:Content> tag for the holderFooter content place holder doesn't have anything in it.
I have next inheritance tree:
Site.master <-- Page1.aspx
<-- Project.master <-- Page2.aspx
And I don't know why Page2 display only content of itself and it's master page - Project. But doesn't display a content of Site (as Page1 does) Why? What have I to write for doing that?