Error Parsing attribute 'page' - c#

Keep Getting this error when running Site:
Error parsing attribute 'page': Cannot create an object of type 'System.Web.UI.Page' from its string representation '' for the 'Page' property.
.aspx file:
<%# Page Title="Home Page" Page Language="VB" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class ="Home1">
</div>
</asp:Content>
vb file:
Partial Class _Default
Inherits System.Web.UI.Page
End Class

take out the word page, and just keep Language (you already used it at the start)
Language="VB"

Related

ASP NET Web Forms can not register User Control (ascx)

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).

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"
%>

Does this MakeRedemption.aspx is the parent page for the user control?

I have a aspx page name MakeRedemption.aspx, the code is something as following :
<%# Page Title="Make Redemption" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="MakeRedemption.aspx.cs" Inherits="MakeRedemption" %>
<%# Register Src="~/UserControls/MakeRedemption_SearchGift.ascx" TagName="MakeRedemption_SearchGift" TagPrefix="uc" %>
<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"></asp:UpdatePanel>
<uc:MakeRedemption_SearchGift runat="server" ID="ucSearchGifts" GiftCategoryAvailable="false" /><% /*UnitCostAvailable="true"*/ %>
</asp:Content>
And I have a user control page name MakeRedemption_SearchGift.ascx.
I would like to ask, is the MakeRedemption.aspx consider a parent page for MakeRedemption_SearchGift.ascx ??
And MakeRedemption_SearchGift.ascx is the user control page of MakeRedemption.aspx
Kindly advise.
Yes, it is. After do some research, testing, further with senior advice. It is.

Null Reference Literal Control

I am trying to pass text to a Literal, the parent.master has the ContentTemplateID's and the Child.master has the contentID's, one of them is the literal of form
<asp:Literal runat="server" ID="myLiteral"></Literal>
I am trying to pass it from a UserControl.cs file like this
gooleTrackin = track.GetTrack(track.OrderType.YAHOO);
Literal mpLiteral = (Literal)this.Parent.Page.Master.FindControl("myLiteral");
mpLiteral.Text = gooleTrackin.ToString(); //nullReference here
But it is giving me NulLReference in the last line.
By the way I do not have access to the .cs files of the master pages, it has to be done through the UserControl.
Thank you
ADDITIONAL CODE (THIS IS LOCATED IN THE CHILD.MASTER)
<%# Master Language="C#" AutoEventWireup="true" MasterPageFile="../common/child.master" %>
<%# Register Src="UserControl.ascx" TagName="UserControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="inner"><uc1:UserControl ID="theRceipt" runat="server" Visible="true"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BottomContentTemplate" Runat="Server">
<div style="margin-bottom:30px;">
<asp:Literal ID="myLiteral" runat="server"></asp:Literal>
Back to Home Page
</div>
</asp:Content>
When master page is used, controls from master page are merged into the control hierarchy of page so this can be an issue while finding controls. I will suggest that you try following and see if it works:
Literal mpLiteral = (Literal)this.Page.FindControl("myLiteral");
OR
Literal mpLiteral = (Literal)this.Parent.FindControl("myLiteral");
Otherwise, you may have to try recursive find - see http://www.west-wind.com/weblog/posts/2006/Apr/09/ASPNET-20-MasterPages-and-FindControl
However, I will rather recommend a alternate way - assuming that you have defined your literal control in Child.Master and Child is the name of code behind class for master, you can add an helper method in it such as
public void UpdateMyLiteral(string text)
{
myLiteral.Text = text;
}
And in user control code, invoke the helper method such as
((Child)this.Page.Master).UpdateMyLiteral("xyz");
Note that we are casting master to its code-behind class.

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