Master Page More has more than one content - c#

just now when i was created my master page it gives me this error. The page has one or more asp content that do not correspond withasp content place holder.
What is wrong with my master page? Here is my code of master page. Thank you.
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"
Inherits="MasterPage" %>
<!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>Master</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1
{
height: 63px;
}
.style3
{
height: 101px;
font-size: xx-large;
font-weight: 700;
font-family: Tahoma;
text-align: center;
color: #FFFFFF;
}
.style6
{
width: 146px;
height: 592px;
}
.style7
{
width: 897px;
height: 592px;
}
.style8
{
height: 592px;
}
.style9
{
font-size: small;
height: 101px;
border-left-color: #808080;
border-right-color: #C0C0C0;
border-top-color: #808080;
border-bottom-color: #C0C0C0;
background-color: #996633;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%; height: 623px; margin-bottom: 0px;">
<tr>
<td bgcolor="#996633" class="style3" colspan="3">
Malaysia Car Booking System<br />
<span class="style9">Your satisfaction is our Priority</span></td>
</tr>
<tr>
<td bgcolor="#CC6600" class="style6">
</td>
<td bgcolor="#FF9900" class="style7" style="vertical-align: top">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</td>
<td bgcolor="#CC6600" class="style8">
</td>
</tr>
<tr>
<td bgcolor="#996633" class="style1" colspan="3">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

What's wrong is that you have a Content tag in your content page that doesn't have a corresponding ContentPlaceHolder tag in the master page.
The only ContentPlaceHolder tag in the master page is in the head tag. It is quite uncommon to not have any in the body tag, as it makes it hard to introduce any body content from the content page. You have a PlaceHolder tag in the body that you perhaps meant to be a ContentPlaceHolder tag?

It would appear that your page has <asp:content> tags which do not correspond to <asp:ContentPlaceHolder> controls in your MasterPage.
For this type of solution, master pages never support comments in the format <!-- -->
This could be causing your error.

I got the same error when I created a very simple master page and let visual studio create a normal page based on that master page. After running the website, the error message disappeared. It seemed like the error message was based on the old master page and that visual studio used the changed master page only for verification once the website was actually run. Strange :-(

You need to include runat = "server" in title tag most of the time it solve the problem

Related

get the iframe element in C#

I'm trying to get the id of the second iframe which is iframe2 in the codebehind to add some css styling. This is my html:
<body>
<form id="Form1" method="post" runat="server">
<table id="Table1">
<tr>
<td>
<iframe id="iframe1">
</iframe>
<uc1 id="uc1"></uc1>
</td>
</tr>
<tr>
<td>
<asp:Panel id="Panel">
</asp:Panel>
<uc1 id="uc2">
</uc1>
</td>
<td>
<iframe id="iframe2">
</iframe>
</td>
</tr>
</table>
</form>
</body>
For some reason I'm not able to get the iframe id in C#. How can I do that please?
Accessing the Iframe
Ensure that you add the runat="server" attribute to the <iframe>:
<iframe id="iframe2" runat="server"></iframe>
This will enable to to access it in your code-behind via the FindControl() method:
// Access your iframe
var iframe = FindControl("iframe2");
iframe.Style.Add("border", "2px solid red");
Or directly by using its assigned id:
iframe2.Style.Add("border", "2px solid red");
Regarding Styling
You mention that you are explicitly trying to style this element. If that is the case, you should likely be using CSS as opposed to setting inline styles on the <iframe> element itself.
For instance, you could apply styles as such to target that element:
<style type='text/css'>
#iframe {
/* Place your styles here (i.e. border: 4px solid red, etc.) */
}
</style>
It's worth noting that actually styling an <iframe> is going to only style the element itself, as the content that is rendered within it is essentially "sandboxed" within the element and won't be affected by some of the assigned styles.
Change the IFrame to have runat="server" you can then get to it on the server side.
<iframe ID="MyIframe" src="" runat="server"></iframe>
You can set set items in C#.
MyIframe.Attributes["src"] = Page.ResolveClientUrl("~/ThisOtherPage.aspx");
MyIframe.Attributes.Add("style", "cursor:pointer;");

Unable to find element when html document is inside an iframe

<div class="reporting-graph-zone">
<input id="ctl00_m_g_a3080099_ed02_44e3_afe2_e6b89d1a2cee_ctl00_hiCulture" name="ctl00$m$g_a3080099_ed02_44e3_afe2_e6b89d1a2cee$ctl00$hiCulture" value="culture=en-US" type="hidden">
<iframe src="/PL/__LI_Partners/FederationMetadata/WIF.axd?ReturnUrl=%2frdPage.aspx%3frdReport%3dSingleDashboard%26culture%3den-US" style="">
<!DOCTYPE html>
<html id="yui_3_1_1487760521746_220" class="yui3-js-enabled" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:rdxslextension="urn:rdXslExtension" style="cursor: auto;">
<head>
<body id="yui_3_1_1487760521746_219" onload="rdBodyLoad()">
<div id="yui_3_1_1487760521746_369" class="yui3-widget rdquicktip yui3-widget-positioned rdquicktip-hidden" style="left: 0px; top: 0px;">
<form id="yui_3_1_1487760521746_218" name="rdForm" method="POST">
<table id="rdRows-1" class="rdDashboardPanelContainer" style="width:100%;" cellspacing="0">
<tbody id="yui_3_1_1487760521746_215">,
<tr id="rdDashboardMenu">
I am unable to find element "rdDashboardMenu" when html document is inside an iframe.
Could anyone help me out?
You should first select frame using below code:
driver.switchTo().frame(0);
After switching frame select element

Alternate of Popup Window (Same functionality)

I am working on a website (C#, .Net 3.5 Framework) and looking for an alternate of Popup window to avoid the popup blocker settings of browsers or in other words want to remove the dependency of popup blocker for Website. Many users disable them because they don't like it.
I am using Master page for Menus and common interface of website.
But all the requirements are same.
Overlapped window
Common Interface/component that can be used to display the content of other HTML/ASPX page
Value can be passed and returned to the Opener Window.
Which is the best option for this scenario?
Thanks.
Your best bet is javascript, maybe modal plugin of jquery, but... The problem is, that it isn't 100% reliable as well. Many people disable javascript or maybe don't have a browser with that js (some older mobile phones etc.).
I have found a way, as an alternate of popup window.
Style Sheet (Popup related CSS)
Purpose: CSS for popup window
.PopupOuterDiv
{
height:100%;
width:100%;
top:0px;
left:0px;
background-color:#000000;
filter:alpha(opacity=50);
-moz-opacity:.50;
opacity:.50;
z-index:50;
}
.PopupInnerDiv
{
position:fixed;
background-color:#ffffff;
z-index:50;
left:25%;
right:25%;
top:25%;
border-right: #0066ff 5px solid;
border-top: #0066ff 5px solid;
border-left: #0066ff 5px solid;
border-bottom: #0066ff 5px solid;
font-family: Arial;
}
.PopoupTitle
{
background-color: #0066ff;
height:25px;
color: white;
}
.PopoupButton
{
color: #ffffff;
width:20px;
border:white 1px solid;
background-color: #663300;
}
Master Page
Purpose: Contains the Common code for popup
1. Create 1 Div for Outer faded Effect
2. Create Div as container or popup Window
3. Create Iframe inside a container DIV and assign the URL.
<div class="PopupOuterDiv" runat="server" id="PopupOuterDiv" style="display:none;"></div>
<div class="PopupInnerDiv" runat="server" id="PopupInnerDiv" style="display:none;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="PopoupTitle">
<td id="PopoupTitle"></td>
<td align="right">
<input class="PopoupButton" type="Button" value="X" onclick="closePopup();" />
</td>
</tr>
<tr style="height:8px;" ><td></td></tr>
<tr>
<td colspan="2">
<iframe id="PopupIframe" src="" runat="server" height="300px" width="480px"></iframe>
</td>
</tr>
</table>
</div>
JavaScript to open and close the Popup
function closePopup()
{
document.getElementById('<%=PopupOuterDiv.ClientID%>').style.display = 'none';
document.getElementById('<%=PopupInnerDiv.ClientID%>').style.display = 'none';
}
function openPopup(PopupTitle, PopupURL)
{
document.getElementById('<%=PopupOuterDiv.ClientID%>').style.display = '';
document.getElementById('<%=PopupInnerDiv.ClientID%>').style.display = '';
document.getElementById('PopoupTitle').innerText = PopupTitle;
document.getElementById('<%=PopupIframe.ClientID%>').src = PopupURL;
}
Content Page
Call the popup window from any content page.
openPopup('My Custom Popup', '../aspx/User.aspx');

ASP.NET simple div position

I need to show a div like in this image (top), but I have this ugly version (bottom):
At the moment I am using this code:
<asp:Repeater ID="DataViewer" runat="server">
<ItemTemplate>
<div style='border: 0px; width:600px;'><%# Eval("DriverId") %>
<div style='border: 3px solid black; width:<%# Eval("OrderCount") %>cm;'><%# Eval("OrderCount") %>
<div style='border: 0px; background-color: red; width:<%# Eval("OrderCountWhereNameIsNotNull") %>%;'>
<%# Eval("OrderCountWhereNameIsNotNull") %>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
How can I solve this?
<%# Eval("DriverId") %>
%;'><%# Eval("OrderCount") %> %;'> <%# Eval("OrderCountWhereNameIsNotNull") %>
you must use '%' instead of cm.
Hope this will solve your problem.
<div style='border: 0px; width:600px;'><%# Eval("DriverId") %>
<div style='border: 3px solid black; width:<%# Eval("OrderCount")
Something wrong there with syntax because color mismatched. In this case its better to delete this tag and write it again.

Master page image doesn't display on content page

I have an image on my master page like this:
<img src="../Images/logo.jpg" />
The master page lies in Root/MasterPages/masterpage.master
Now this image is displayed in a content page which is in Root/SomeDir/ContentPage.aspx,
but it doesn't work in a content page which is in Root/SomeDir1/SomeDir2/ContentPage.aspx. Why?
Master Page HTML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
#div_Main
{
height: 825px;
width: 1022px;
top: 16px;
left: 77px;
position: absolute;
margin-left: 14px;
}
#div_LeftPanel
{
width: 299px;
top: 179px;
left: 2px;
position: absolute;
height: 641px;
background-color: #7E8387;
}
#div_Content
{
width: 716px;
top: 180px;
left: 303px;
position: absolute;
height: 638px;
}
#div_Header
{
top: 0px;
left: 0px;
position: absolute;
height: 176px;
width: 1022px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="div_Main">
<div id="div_Header">
<img src="../Images/logo.jpg" />
</div>
<div id="div_Content">
<asp:ContentPlaceHolder ID="cph_WorkingArea" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="div_LeftPanel">
<br />
<br />
<br />
<br />
<br />
<asp:LinkButton
ID="lnkbtn_JObAspirantsList" runat="server"
style="color: #CFCFF3; font-size: xx-large"
onclick="lnkbtn_JObAspirantsList_Click">Job Aspirants List</asp:LinkButton>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:LinkButton ID="lnkbtn_ERFList" runat="server"
style="color: #CFCFF3; font-size: xx-large" onclick="lnkbtn_ERFList_Click">ERF List</asp:LinkButton>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:LinkButton ID="lnkbtn_InterviewFeedbackList" runat="server"
style="color: #CFCFF3; font-size: xx-large"
onclick="lnkbtn_InterviewFeedbackList_Click">Interview FeedbackList</asp:LinkButton>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:LinkButton ID="lnkbtn_NewEmployeeList" runat="server"
style="color: #CFCFF3; font-size: xx-large"
onclick="lnkbtn_NewEmployeeList_Click">New Employees List</asp:LinkButton>
<br />
<br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" style="color: #CFCFF3; font-size: xx-large" onclick="LinkButton1_Click">LogOut</asp:LinkButton>
<br />
<br />
</div>
</div>
</form>
</body>
</html>
Content Page HTML
<%# Page Language="C#" MasterPageFile="~/MasterPages/HRMaster.Master" AutoEventWireup="true" CodeBehind="ERF.aspx.cs" Inherits="StarTechnologies.ERF" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cph_WorkingArea" runat="server">
<p>
<br />
<asp:GridView ID="GridView1" runat="server" Height="212px"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="434px">
</asp:GridView>
</p>
<br />
</asp:Content>
RPM1984 is almost right. You should use ~ to indicate a path relative to the root of your application. You should however translate that to a path the browser understands. If you are using ASP.NET controls like Image that is done automatically. If you're using HTML tags (without runat="server") you have to translate the path manually using Page.ResolveClientUrl().
For example:
<img src="<%= ResolveClientUrl( "~/Images/logo.jpg" ) %>"/>
In this case however, you're probably better off using the Image control:
<asp:Image runat="server" ImageUrl="~/Images/logo.jpg"/>
Try not to use relative paths.
Use absolute:
<img src="~/Images/logo.jpg" />
That is assuming "Images" is a folder underneath the root of your web application.
The thing to remember about Master Pages is that they really are syntactic sugar in a way (similar to partial classes) That is, when you put an image inside a MasterPage, the .NET CLR will create the content page with the Master info - so the image reference will be unchanged.
It's not ../Images from the Master, its ../Images from the Content it's placed upon.
In other words, to the client, there is only ONE page (ASPX - content page), it's not like a magical parent page has been created which holds onto URL references.
HTH
I had the same problem.
My master page's content didn't display but the Web Form content did.
What happens is that the content page is overwritting the master page's content.
I solved it creating a new ContentPlaceHolder in the MasterPage with ID="Example".
Then in the Web Form, I changed ContentPlaceholderID="OlderID" to ContentPlacerHolderID="Example".

Categories

Resources