Webforms and Template Inheritance parameters - c#

Hi I'm learning a bit of webforms for a sharepoint 2010 module I'm helping with.
I've got a background with razor and enjoy inheriting templates and then using parameters set in the controller to influence the layout.
So in my system I've got a similar setup.
Index.aspx with
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="CESA19Template.Layouts.CESA19Template.Index" MasterPageFile="ValidationTemplate.master" %>
ValidationTemplate.master with
<%# Master Language="C#" MasterPageFile="../Template/Template.master" AutoEventWireup="true" %>
and the master with
<%# Master Language="C#" %>
I would like to add a parameter into the .cs behind ValidationTemplate (ValidationTemplate.master.cs) and then use that in the template as well as have my Index.aspx page change the parameter.
I've tried loads of CodeBehind and all sorts can someone help me, or isn't this possible and needs another way? (maybe a include)

I managed to solve this - basically you need to get the public key from the file behind it and then this works.
<%# Master Language="C#" MasterPageFile="../Template/Template.master" AutoEventWireup="true" Inherits="CESA19Template.Layouts.CESA19Template.ValidationTemplate,CESA19Template,Version=1.0.0.0, Culture=neutral, PublicKeyToken=68cf004eb48f0fd4"
I guess this is probably sharepoint 2010 being a bit daft.

Related

Html does not exist in current context. Can I use html class in web forms using Web View syntax?

I am programming an app that has some sections in WebForms and some in MVC. I have a Webform.master and a Site.Master. When using the Html class, My Webform.master in visual studio says "The name html does not exist in the current context." but I don't get that error in site.master file, and html is used many times there.
Both the site.master and webform.master are in the views/shared directory.
EDIT: my purpose is to render a partial view in webforms. I'm unable to do that because html is not recognized in webform.master. If there's an alternate way to render a partial view, I'd use that if possible.
This is the Webform.master.
<%# Master
Language="C#"
MasterPageFile="~/Views/Shared/Root.Master"
AutoEventWireup="true"
CodeBehind="Webform.master.cs"
Inherits="JCIMS_MVC2_EF.WebUI.Views.Shared.Webform"
%>
<%# Register src="SupportPartial.ascx" tagname="SupportPartial" tagprefix="uc1" %>
This is the Site.master.
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Root.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>
The Html methods are all part of the HtmlHelper class which is a feature of MVC.
The first line of site.Master is telling your page to inherit from System.Web.Mvc.ViewMasterPage which will give you access to the MVC namespace and the HtmlHelper you're looking for.
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Root.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>
Your Webform.master page inherits from JCIMS_MVC2_EF.WebUI.Views.Shared.Webform as you can see from the first line. So you will not be able to use the HtmlHelper here.
<%# Master
Language="C#"
MasterPageFile="~/Views/Shared/Root.Master"
AutoEventWireup="true"
CodeBehind="Webform.master.cs"
Inherits="JCIMS_MVC2_EF.WebUI.Views.Shared.Webform"
%>

Page isn't taking masterpage design

The problem that i'm having is that i made a master page like i always do. Then i add a views folder and add a web form using master page. But the design from the master page isn't showing on newly made web form.
<%# Page Title="Home - " Language="C#" MasterPageFile="~/App_Themes/Theme/shop.Master" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="Shop.Views.home" %>
You need to check "set masterpage" when you are adding a new webform in visual studio.

asp.NET - Exclude a Page from Sitemaster or make it follow a different Site Master

I have two pages I want to exclude them from the sitemaster so I can add a check for the session in the sitemaster. I want to exclude them because I want that the 401.aspx page and another page can be accessed by anyone. But the rest should be checked for and authenticated.
Is this possible, and what is the best solution to do this?
Just don't add a MasterPageFile="~/Master.master" statement to your pages (or reference another MasterPage here)
Default:
<%# Page Language="C#" MasterPageFile="~/Master.master" [...] %>
"Special" pages:
<%# Page Language="C#" MasterPageFile="~/AnotherMasterPage.master" [...] %>
Without master:
<%# Page Language="C#" [...] %>
If i understood your question your problem is how to handle errors and redirect to specific files when that happens. This may help http://www.asp.net/hosting/tutorials/displaying-a-custom-error-page-cs and http://msdn.microsoft.com/en-us/library/aa479319.aspx
But if your problem is how to remove master pages from a specific file , you can simply remove it's refrence from your aspx file. remove the MasterPageFile="/Master/default.master"
from your <%# Page Language="C#" ...%>
Hope this helps.

MVC2 nested master could not load type?

I've just begun experimenting with nested masters in MVC2. I'm not quite sure why I am getting this error.
Parser Error Message: Could not load type 'MySite.Views.Shared.Master'.
I used the add item wizard, created Master.master, and selected it's master to be Site.Master. In one of my views I changed the MasterPageFile from Site.Master to Master.master. I haven't changed any contents. What have I gotten wrong?
It sounds like you've added a Master Page and not a MVC Master Page. You need to make sure that both of your master pages inherit from System.Web.Mvc.ViewMasterPage.
So your master page directives should look like this:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
AND
<%# Master MasterPageFile="~/Views/Shared/Site.Master" Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
HTHs,
Charles

CS0103: The name 'rGrid' does not exist in the current context

I have an ASPX Page:
<%# Page Language="C#" MasterPageFile="~/site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="myProject.Presentation.Web.Default" src="Default.aspx.cs" %>
<%# MasterType VirtualPath="~/site.Master" %>
...
<asp:Repeater ID="rGrid" runat="server">
<ItemTemplate>
...
</ItemTemplate>
</asp:Repeater>
With this Master:
<%# Master Language="C#" AutoEventWireup="true" Codebehind="site.master.cs" Inherits="myProject.Presentation.Web.master" src="~/site.Master.cs" %>
When I try to access one of the members on the page:
namespace myProject.Presentation.Web {
public partial class Default : System.Web.UI.Page
...
rGrid.DataSource = myProject.Business.User.GetReports(UserId, true);
I get this YSOD on that line:
CS0103: The name 'rGrid' does not exist in the current context
Yet Intellisense and Object Exporer say it's valid. Why is that?
Is this a website or web app?
If it's a web app, delete your designer files, then right click on your aspx page and/or master page and select convert to web app. This will rebuild the designer files.
This is nonsense, canned the project and redoing it as a website project.
This error generally occurs when variable declerations and variable usage are in different scopes. Check *.aspx.cs file and designer file namespace , namespaces must be same..

Categories