I am creating a Web Forms project with a Master Page. However, when I put a label on the master page (or any other control or html element) it does not display it on the web form. How can I fix this problem?
MasterPage:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="RWA.MasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form" runat="server">
<div>
<asp:ContentPlaceHolder ID="MasterPagePlaceHolder" runat="server">
<asp:Label ID="NameLabel" runat="server" Text="Label"></asp:Label>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Web Form:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master"
AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="RWA.Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MasterPagePlaceHolder"
runat="server">
</asp:Content>
Fixed it, only needed to remove the control from the content placeholder
Related
I have googled and have search this forum, i can not find solution to my problem. As stated by the title in my webforms project using vs 2015 both these mentioned controls are causing a full page post back after uploading is done. In my other projects this works fine. But in this particular one i cant figure it out. Is there just a common thing I am over looking, I have created fresh pages with out using the master-page I still get the same results - full post back. I did not post my code because i am using the controls as any other programmer would.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="pic1.aspx.cs"
Inherits="SSWebAppV1._1.pic1" %>
<%# Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
Width="500px" AllowedFileTypes="jpg,jpeg,png" MaximumNumberOfFiles="4"
OnUploadComplete="AjaxFileUpload1_UploadComplete" />
</div>
</form>
</body>
</html>
****code-behind***
protected void AjaxFileUpload1_UploadComplete(object sender,
AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string fileName = Path.GetFileName(e.FileName);
AjaxFileUpload1.SaveAs(Server.MapPath("~/Eimages/" + fileName));
}
I have a master page Header.master which contains a logout button, due to this reason I have to include a form with run at server in my master form.
Again I am using a form in my page because I want to use controls and asp.net compiler says that you cant use controls with form tag with run at server.
Header.master
<form runat="server"><asp:ImageButton ID="btn_logout" runat="server" OnClick="btn_logout_Click" Height="22px" ImageUrl="~/img/logout.png" Width="43px" /></form>
My Page
<%# Page Title="" Language="C#" MasterPageFile="~/Header.Master" AutoEventWireup="true" CodeFile="student_registration.aspx.cs" Inherits="SCMS.student_registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form id="frm_sr" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel>
</form>
</asp:Content>
Remove Form tag from your page (My Page)
<form id="frm_sr" runat="server">
Form tag in master page is already enclosing all the code written in page itself
(<asp:Content ID=...>)
I keep get an error when I load a ContentPage inside a fancybox:
Cannot find ContentPlaceHolder 'ContentPlaceHolder1' in the master page '/MasterPage/Modal.Master', verify content control's ContentPlaceHolderID attribute in the content page.
I have this in the MasterPage (some code omitted for simplification):
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Modal.master.cs"
Inherits="TransportadoraEDI.App.Modal" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8" />
<title></title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="main-content">
<div style="width: 800px; height: 600px">
<asp:ContentPlaceHolder ID="cphConteudo" runat="server">
</asp:ContentPlaceHolder>
</div>
<!-- jQuery -->
<script src="../js/jquery.min.js"></script>
<script src="../js/init.js"></script>
<asp:ContentPlaceHolder ID="cphBlocoJs" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
And this code in a ContentPage (some code omitted for simplification):
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage/Modal.Master"
AutoEventWireup="true" CodeBehind="FormCadNotFis.aspx.cs" Inherits="TransportadoraEDI.App.Conemb.FormCadNotFis" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphConteudo" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphBlocoJs" runat="server">
</asp:Content>
How it's possible to the ContentPage look for a ContentPlaceHolder that doesn't even exists?
EDIT
My open fancybox function:
$(document).ready(function () {
function AbrirModal(url) {
$.fancybox.open({
fitToView: false,
autoSize: false,
href: url,
//width: _width,
//height: _height,
type: 'iframe',
transitionOut: 'none',
centerOnScroll: true,
hideOnOverlayClick: false,
padding: 0,
afterClose: function () {
parent.location.reload(true);
}
});
}; });
There is no ContentPlaceHolder named 'MainContent' in your master page,
A content place holder should be in your Master page like this:
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
And child pages like this:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
I have a scenario like this (simplified for this question):
I have a master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Ads.master.cs" Inherits="ActiveDigitalSignage.Ads" %>
<!DOCTYPE html>
<html>
<head>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div class="wrapper">
<form id="form1" runat="server">
<header>
</header>
<section>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</section>
</form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<asp:ContentPlaceHolder ID="script" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>
I have a default.aspx page:
<%# Page Title="" Language="C#" MasterPageFile="~/Ads.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div><p>Test</p></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
</asp:Content>
The way its setup is, any header stuff can go in the "head" section. The main stuff goes in the "ContentPlaceHolder" and any javascript goes into the "script" place holder. Everything is working fine as is right now.
The issue I'm running into is I want to use a User Control (.ascx) in my Default.aspx page. However there is javascript in the user control. Because the jQuery is at the bottom of the page (in the "script" section), the javascript in the user user control is breaking. Is there a way to make the javascript in the user control render inside the "script" placeholder?
I know I can just copy and paste the code into a .js file and load the javascript in my master page. The problem with doing that is there are a bunch of ASP.NET tags (e.g. <%= %>) in the javascript that reference controls in the user controls, so copying and pasting this into a .js file would break this.
I'm thinking, off the top of my head, there might be a way in the global.asax page, during prerender, that can detect javascript in a user control and dynamically move it into the proper section?
I have 2 master pages that are nested.this is main master page code for example:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPageMaster.master.cs" Inherits="MasterPageMaster" %>
<!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 runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtMasterPageMaster" ClientIDMode="Static" runat="server"></asp:TextBox>
<div style="background-color:Aqua;height:40px;">
Some Text
</div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
and the nested master page:
<%# Master Language="C#" MasterPageFile="~/MasterPageMaster.master" AutoEventWireup="true"
CodeFile="MasterPageNested.master.cs" Inherits="MasterPageNested" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Panel runat="server" ID="panelMain" BackColor="lightyellow">
<h2>
Child master</h2>
<asp:Panel runat="server" ID="panel1" BackColor="lightblue">
<p>
This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent1" runat="server" />
</asp:Panel>
<asp:Panel runat="server" ID="panel2" BackColor="pink">
<p>
This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent2" runat="server" />
</asp:Panel>
<br />
</asp:Panel>
</asp:Content>
and I create a page based on this nested master page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPageNested.master" AutoEventWireup="true" CodeFile="PageMasterPageNested.aspx.cs" Inherits="PageMasterPageNested" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ChildContent1" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ChildContent2" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" Height="66px"
onclick="Button1_Click" Width="196px" />
</asp:Content>
I want in click of Button1 get text of main master page.
How I can do this?
In PageMasterPageNested.aspx:
TextBox txtBox = this.Master.Master.FindControl("txtMasterPageMaster") as TextBox;
Should work. Give it a try. Hope it helps.
This works in any case. especially if you dont know or care how many master pages you nested. Hope it helps :)
MasterPage tmp = this.Master;
while (tmp.Master != null)
{
tmp = tmp.Master;
}
var control = tmp.FindControl("form1");