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..
Related
I have a user control with the following directive
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="SelectorControl.ascx.cs" Inherits="SelectorControl" %>
and then I can register this control in any .aspx and use, like this
<%# Page Language="C#" AutoEventWireup="True" CodeBehind="FolderDistribution.aspx.cs"
Inherits="SearchFolder.FolderDistribution" %>
<%# Register TagPrefix="UC" TagName="TemplateSelection" Src="~/Controls/SelectorControl.ascx" %>
<div>
<UC:TemplateSelection ID="templates" runat="server" />
</div>
But, I need to set CodeFile in my UserControl (ascx) instead of CodeBehind. In control's directive I changed
CodeBehind="SelectorControl.ascx.cs" to CodeFile="SelectorControl.ascx.cs"
And in this case I get the following runtime error
The base class includes the field 'templates', but its type (TemplateSelection) is not >compatible with the type of control (ASP.controls__templateselection_ascx).
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"
%>
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.
ReSharper (7.1.25.234) does the wrong thing when adding register directives.
Create /Controls/ComplexField.ascx
In APageWithABunchOfFields.aspx, refer to the new control:
<%# Page Title="A page with a bunch of fields" Language="C#" MasterPageFile="~/Layouts/Site.Master" %>
<myproj:ComplexField runat="server" />
ReSharper offers to generate a <%# Register %> directive, which leads to this:
<%# Page Title="A page with a bunch of fields" Language="C#" MasterPageFile="~/Layouts/Site.Master" %>
<%# Register TagPrefix="myproj" Namespace="MyProject.Controls" Assembly="MyProject" %>
<myproj:ComplexField runat="server" />
The problem is, that won't find or execute ComplexField.ascx (note though that a ComplexField instance does get contructed). What ReSharper should generate is:
<%# Page Title="A page with a bunch of fields" Language="C#" MasterPageFile="~/Layouts/Site.Master" %>
<%# Register TagPrefix="myproj" TagName="ComplexField" Src="~/Controls/ComplexField.ascx" %>
<myproj:ComplexField runat="server" />
In other words, ReSharper is registering the control by namespace instead of by source path. The issue ReSharper causes is that ASP.NET doesn't execute the ComplexField.ascx file when the page is loaded!
Is this a bug/missing feature in ReSharper or a problem with my understanding of Register directives?
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.