How to share Master Pages between my projects - c#

I'm working on a Web Project and I need to share one master page so that when I create a new page, it has the basic layout.
What i've thought is to create a project with that master page and, in each web project, add it as a reference.
But the problem is that i don't know how to embed the master page in the .aspx file that I want to apply the MP, or if it's the best way of sharing master pages between projects.
I'll apreciate any help or comment!
Here I give you my code (this doesn't work):
Index.aspx:
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="" CodeBehind="Index.aspx.cs" Inherits="MiWeb.Index" %>
<HeaderMp:Header ID="ctntHead" ContentPlaceHolderID="head" runat="server">
<title>SITPer</title>
</HeaderMp:Header>
Header.Master:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Header.Master.cs" Inherits="MasterPages.Header" %>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.dropotron.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-layers.min.js"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-desktop.css" />
</noscript>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div>
<!-- Header -->
<div id="header-wrapper" >
<div id="header">
<!-- Logo -->
<div id="logo">
<h1>SITPer</h1>
<p>Prueba</p>
</div>
</div>
</div>
<asp:ContentPlaceHolder ID="body" runat="server">
</asp:ContentPlaceHolder>
</div>
</body>
</html>
Thanks!!

NOTE: In addition to the linked files feature described here, there is a new shared project feature in Visual Studio 2015+ that allows you to create a project exclusively for sharing code that will be compiled into the project it is added to.
Master pages can only belong to a single web project. However, there is a feature of Visual Studio/MSBuild that allows you to share the code between projects to effectively get the desired result. If you put the master page files (all of them including .master, .master.cs and .master.designer.cs) into a folder at the same level as your solution you can use the linked file feature of Visual Studio to add the file as a linked file (one that is not copied into the project folder).
In Windows Explorer, open up the directory that has your solution (.sln) file. Right click in the whitespace and click New -> Folder. Name the folder SharedFiles. Copy the Header.master, Header.master.cs and Header.master.designer.cs files into the folder.
In Visual Studio, delete the Header.master file(s) from all of the projects. Then follow these steps for each project you want to share the Header.master page in.
Right-click on the project you wish to share the file in Solution Explorer, and click Add -> Existing Item.
In the Add Existing Item dialog, navigate to the SharedFiles folder.
Highlight the Header.master, Header.master.cs and Header.master.designer.cs files.
In the bottom right corner of the Add Existing Item dialog, click the down arrow next to the Add button (not the Add button itself!), and click the Add As Link item in the dropdown.
If you did it correctly, the icon of the file will have an arrow on it to indicate that it is a linked file. Now when you make changes to the master page, the changes will be reflected in all of the projects.
You also have an issue that you must fix in your Index.aspx page. You must set the master page file to the virtual location of the file. If you follow the instructions above, the path will be...
MasterPageFile="~/Header.master"
But note that the virtual path will change if you put the file (or the linked file) in a subdirectory of your web project.

i think you are not adding the address of your masterpage in your page (MasterPageFile="").
are you using visual studio?
if you are then you just need to use
ctrl+shift+a and select web form using masterpage.
Master Page:
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="WebApplication2.Site1" %>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
Page.aspx which uses masterpage:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Registration Form.aspx.vb" Inherits="WebApplication2.Registration_Form" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

Related

content placeholders pages not showing inside master page

I'a currently working on C# aspx.net project, and all of a sudden the pages that should load inside master page are not shown, it's like "hidden", only master page is showing, i didn't do nothing revelant to it, i think.
It's getting me insane because i already loaded a backup that i got, and the same problem occurs. So maybe i did something wrong to my Visual Studio 2019?
Does that ever happened to anyone?
I've tryed to change the Netframework from 4.5 to 4.6 but the problem persists.
if i inspect the page on google devtools, the page's are there, but not showing on the content placehonder.
Example of my master page:
<%# Master Language="C#" AutoEventWireup="false" CodeBehind="Masterpage.Master.cs" Inherits="WORKFLOW_FACTURE.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
....
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div id="wrapper">
</div>
<div id="page-wrapper">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<!-- /#page-wrapper -->
</body>
</html>
example of one page that should be loaded whenthe user enter the masterpage:
<%# Page Title="" EnableEventValidation="false" Language="C#" AutoEventWireup="false" MasterPageFile="~/Masterpage.Master" CodeBehind="Indicateurs.aspx.cs" Inherits="WORKFLOW_FACTURE.Indicateurs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form runat="server">
....
</form>
<script type="text/javascript">
...
</script>
</asp:Content>
I alredy had that same problem on my asp.net application, where bootstrap classes weren't recognized.
It can happen for two main reasons:
1 - *the links *.css / script .js are being called from the master page at bad order, and because of that, dind't load properly.
2 - Calling bootstrap.css instead of bootstrap.min.css, that happened to me, i think that's because of the load time that can be relevant to the content page.

Why doesn't Visual Studio Default.aspx file let me add HTML elements?

<%# 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.

CKEditor on ASP.NET C#

Trying to integrate CKEditor into my asp.net application....
I downloaded both CKEditor 3.x and the CKEditor for ASP.NET control and added the CKEditor reference to the site I also this to the application
<%# Page Language="C#" AutoEventWireup="true" CodeFile="CKEditor.aspx.cs" Inherits="CKEditor" %>
<%# Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<!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>CKEditor</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server">
</CKEditor:CKEditorControl>
</div>
</form>
but I am getting this error.
CS0426: The type name 'NET' does not exist in the type 'CKEditor'
<%# Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
I have searched all through the internet for solutions but it seems I am the only one having this kind of problem...please can someone help.
You have named your aspx file as CKEditor, the same name as your control assembly name having a namespace with same name, so there is a collision.
Try changing your aspx name to something else such as CKEditorTest.aspx instead of CKEditor.aspx
Its always better NOT to name your project, solution, class, control, literal, namespace etc. by any of the reserved keywords or other existing controls, classes, namespaces.
Add a reference to the CKEditor for ASP.NET Control to your website.
In Visual Studio use the Add Reference command and browse to bin\Release\CKEditor.NET.dll file from the unpacked CKEditor for ASP.NET installation package. You can also manually copy the DLL file to the bin folder of your application.
Ref: http://docs.cksource.com/CKEditor_3.x/Developers_Guide/ASP.NET/Integration_Advanced
I'am using VS 2017 and CKEditor 4.12.
First, no need to integrate this:
<%# Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
and consequently this:
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server">
</CKEditor:CKEditorControl>
You only need the following code in your web page:
<script src="../Scripts/ckeditor/ckeditor.js" ></script>
<textarea name="editor1" id="editor1" rows="10" cols="80">
</textarea>
<div >
<script>
CKEDITOR.replace( 'editor1' );
</script>

Where are navigation elements declared in default Web Forms template?

VERY very basic question. I'm trying to learn ASP.NET. I created a default website1 in VS 2013 Community I get a ton of files. When I run the app in IS, the default.aspx web page appears and all is OK, but above the web page is a banner with links to contact.aspx, login.aspx. register.aspx, etc. and I cannot find where that banner is? It's not on default.aspx. Where is it? Seaching the project for "Contact.aspx" only returns one result, the page itself, as an example.
It's probably coming from a Master Page. Look at the <%# Page %> header at the tops of the .aspx files. You'll see they reference a master page. A Master Page is used to provide structure to the site. It means you don't have to write the same HTML for common elements on every single content page. Content pages (.aspx) then can have their content inserted into the Master Page. And yes, you can nest master pages. This is all done through the <asp:ContentPlaceHolder /> (higher level Master Page) and <asp:Content /> (nested Master Page or Content Page) tags.
Let's look at an example:
MasterPage.master
<%# Master Language="C#" %>
<!DOCTYPE html>
<html>
<head runat="server" >
<title>Master page title</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="Main" runat="server" />
</div>
<div>
<asp:ContentPlaceHolder id="Footer" runat="server" />
</div>
</form>
</body>
</html>
Default.aspx
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content here.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" runat="Server" >
Footer content here.
</asp:Content>
The resulting HTML will look like this on the client when you access Default.aspx:
<!DOCTYPE html>
<html>
<head>
<title>Content Page 1</title>
</head>
<body>
<form id="ContentPage_form1">
<div>
Main content here.
</div>
<div>
Footer content here.
</div>
</form>
</body>
</html>
Take special note of how the ID of the form changed from the server side to the client. This trips a lot of people up when they start doing client side JavaScript. If you want the ID to not change, you have to add the ClientIDMode="Static" attribute to the control (you can also set it at page, web.config, or machine.config levels).

Regarding customizing telerik radEditor skin

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<link href="Skins/CustomSkin/Editor.Default.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:RadEditor ToolbarMode="Default"
ID="editor1" runat="server" EnableEmbeddedSkins="false" Skin="CustomSkin">
</telerik:RadEditor>
</asp:Content>
RADEditor on my page was inheriting Master Page's CSS properties so followed this tutorial to create custom skin..now what I did was...I simply copied the Folder named "Default" under Skins folder and renamed it to "CustomSkin" and added it like in the code above ..thot it would work but it didn't coz now I don't see border on my RADEditor...why is that ? Also it is STILL inheriting properties from Master page's CSS file :(
I didn't change name of any of the CSS files inside "CustomSkin" folder...Also when I added the following inside "telerik:RadEditor"...still problem persisting..
<CssFiles>
<telerik:EditorCssFile Value="~/Skins/CustomSkin/Editor.Default.css" />
<telerik:EditorCssFile Value="~/Skins/CustomSkin/Window.Default.css" />
<telerik:EditorCssFile Value="~/Skins/CustomSkin/ToolBar.Default.css" />
</CssFiles>
ok got it sorted out myself..CSS needed to be linked properly..made some changes in CustomSkin CSS files and marked some properties as !important so it won't inherit from parent page

Categories

Resources