Unable To See Master Pages While Adding A Page In The Project - asp.net

i am trying to add a .aspx page in the project , but while adding the .aspx page i am not getting the option to choose existing master pages.

Don't know why it is not visible; if you cannot set it, simply add it later manually to the #Page directive of your page.
It's simple:
MasterPageFile="~/Path/To/My/MasterPage.master"
E.g. on top of your ASPX page, write something like:
<%# Page
Culture="auto"
UICulture="auto"
MaintainScrollPositionOnPostback="true"
Title="The Title of your Page"
Language="C#"
MasterPageFile="~/Path/To/My/MasterPage.master"
AutoEventWireup="true"
CodeFile="MyPage.aspx.cs"
Inherits="MyPage"
%>
In addition, if you want to access the derived type of your master page, use the #MasterType directive:
<%# MasterType VirtualPath="~/Path/To/My/MasterPage.master" %>

Could be a bug with VS, try save the project with your master page then close and reopen VS.
If not as Uwe Keim mentioned above it is really easy to add the master page manually.

Related

How do I find out where .aspx page is pulling its header?

I haven't worked with C# or ASP.NET before, but I'm trying to update some .aspx pages on a site. I'm noticing that there are also some updates that also need to be made in the <head> when I look at the source of the page, but I don't know how to determine where that header info is being pulled from to make that change.
Here are the two lines I'm seeing before it jumps into the HTML content:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="DefaultLogin.aspx.vb" Inherits="TIMSSSSO.Web.DefaultLogin" %>
<%# Register TagPrefix="cc1" Namespace="Generic.Foundation.WebControls" Assembly="Generic.Foundation.WebControls" %>
Does any of this tell me where I should go to edit the header? Any guidance would be appreciated.

asp.net mvc render a webform as a partial in a razor view

I'm trying to use the asp.net webforms sitemap and menu control to build my asp.net mvc's sites navigation.
There are many tutorials about embedding razor views into webforms, but I want to go the otherway around. Embed a webform into a razor view.
Doing something like this looks eemi promising:
#Html.Partial("~/Views/Shared/test/menu.aspx")
Which presents an error:
Parser Error Message: 'System.Web.Mvc.ViewUserControl' is not allowed here because it does not extend class 'System.Web.Mvc.ViewPage'.
Is there a value for Inherits that would allow this to work?
Oh Duh, read the error message...
I changed the first line of the webform from this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewUserControl" %>
to this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewPage" %>
Then I ran into another issue about System.Web.Mvc.ViewPage being defined twice, so I deleted the *.designer.cs file and now its working.

Could not load type error in application page

I have created a application page for login functionality in sharepoint by following this post.
But this giving me an error at inheriting the page. I have folder structure and .aspx file like below.
Did I done any mistake while giving the link to the .cs file in the application page?
After I deployed into my site, it is giving me error like below.
I am trying to resolve it from 2 hrs, but unable to find the solution. Can any one suggest me the way to do it please!!
Try to add
<%# Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
before
<%# Page ... %>
Add $SharePoint.Project.AssemblyFullName$ to your Inherits attribute
Instead of <%# Page Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourNamespace.YourPage" %>
Use <%# Page Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourNamespace.YourPage,$SharePoint.Project.AssemblyFullName$" %>
This could also be happened when there are another reference to that assembly which didn't exist. To show the error, simply check Ha Doan answer.

using a masterpage's namespace from content page

Can i use namespace which is imported on masterpage ?
i can import and use namespace on masterpage like that..
<%# Import Namespace="utl=portal.lib.SnkUtilities" %>
and on markup;
<a href='<%= "/" + utl.getSomeString() + "/cart.aspx" %>'>
but if want to use same namespace on a contentpage, i have to import same namespace on content second time as follows:
<%# Page Title="" Language="C#" MasterPageFile="~/Master" AutoEventWireup="true" CodeBehind="Account.aspx.cs" Inherits="portal.secret.Account" %>
<%# Import Namespace="utl=portal.lib.SnkUtilities" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%= utl.getAnotherString() %>
</asp:Content>
Do you have any suggestions ?
Thanks in advance
You are thinking that the master page is read first, but in the page life cycle, the master page is read after the Page Request, so you have to include the namespace in every page. It first looks in the current page and if it does not find it at the compile time, you will get error.
When the page is fetched, the # Page directive is read. If the directive references a master page, the master page is read as well. If this is the first time the pages have been requested, both pages are compiled.
Read from the End of the page Run-time Behavior of Master Pages
Note that the master page becomes a part of the content page. In effect, the master page acts in much the same way a user control acts — as a child of the content page and as a container within that page.

How to add code behind manually on asp.net

I have a website on the IIS but it has only the aspx file. Now I need to add the code behind for some pages. How do I go about this?
I've been trying to add the attribute "codebehind" and "autoeventwireup" on the top of the aspx file but no luck (the page_load event is not being called). Also, if I double click on the button from the design view in Visual Studio, it creates the javascript handle (not the server code).
In your page directive on the aspx page (<%# Page...), you need two pieces:
1) CodeFile="Default.aspx.vb"
2) Inherits="_Default"
In your code-behind file, you need two things:
1) The file name has to be whatever you specified above (CodeFile = "...)
2) the class name has to be whatever you specified above (Inherits="_...)
For example, if your aspx page was named "default.aspx" then your page direction in the aspx page would look similar to this:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
And your code-behind would look similar to this:
Partial Class _Default
Inherits System.Web.UI.Page
End Class
you want the #page directive and the class attribute. MSDN docs here

Resources