分析器错误消息:此处不允许使用'GarageManager.index',因为它不扩展类'System.Web.UI.Page'。!! [英] Parser Error Message: 'GarageManager.index' is not allowed here because it does not extend class 'System.Web.UI.Page'.!!

查看:70
本文介绍了分析器错误消息:此处不允许使用'GarageManager.index',因为它不扩展类'System.Web.UI.Page'。!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,你能帮帮我PLZ,我在index.aspx.cs中出现了这个错误 - 带有母版页的webForm。

这里是我的代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;

使用 System.Web.UI.HtmlControls;

使用 System.IO;

使用 GarageManager.Models;

命名空间 GarageManager.Pages
{
public partial class 索引:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
ProductModel model = new ProductModel();
列表<产品> products = model.GetAllProducts();

if (products!= null
{
foreach (产品产品中)
{
Panel productPanel = < span class =code-keyword> new Panel();
ImageButton imageButton = new ImageButton
{
ImageUrl = < span class =code-string>〜/ Images / Products / + product.Image,
CssClass = productImage
PostBackUrl = string .Format( 〜/ Pages / Product.aspx?id = {0},product.Id)
};
标签lblName = 标签
{
Text = product.Name,
CssClass = productName
};
标签lblPrice = 标签
{
Text = < span class =code-string>£ + product.Price,
CssClass = productPrice
};

productPanel.Controls.Add(imageButton);
productPanel.Controls.Add( new Literal {Text = < br />});
productPanel.Controls.Add(lblName);
productPanel.Controls.Add( new Literal {Text = < br />});
productPanel.Controls.Add(lblPrice);

// 向静态控件添加动态控件
pnlProducts。 Controls.Add被(productPanel);
}
}
else
pnlProducts.Controls.Add( new Literal {Text = 找不到产品!});
}
}
}





这里是我的Html index.aspx

 <%@       标题  =     语言  =  C#    MasterPageFile   = 〜/ MasterPage.Master    AutoEventWireup   =  true    CodeBehind   =  index.aspx.cs   继承  =  GarageManager.index   %>  
< asp:内容 ID = Content1 ContentPlaceHolderID < span class =code-keyword> = head runat = server >
< / asp:内容 >
< asp:内容 ID = Content2 ContentPlaceHolderID = ContentPlaceHolder1 runat = server >
< asp:Panel ID = pnlProducts runat = server >
< / asp:Panel >
< / asp:Content >

解决方案

在您的示例代码中没有这样的东西 GarageManager.index ,仅 GarageManager.Pages.Index !!!

请记住,Inherits属性需要一个完全限定的属性name - 类名前的整个命名空间!!!

 <  ![CDATA [<%@     Page    标题  =    语言  =  C#    MasterPageFile   = 〜/ MasterPage.Master < span class =code-attribute>   AutoEventWireup   =  true    CodeBehind   =   index.aspx.cs   继承  =   GarageManager.Pages.Index     > ]]> 


hello guys, can you help me plz, I got this error in my index.aspx.cs - webForm with master page.
here is my code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.IO;

using GarageManager.Models;

namespace GarageManager.Pages
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ProductModel model = new ProductModel();
            List<Product> products = model.GetAllProducts();

            if (products != null)
            {
                foreach (Product product in products)
                {
                    Panel productPanel = new Panel();
                    ImageButton imageButton = new ImageButton
                    {
                        ImageUrl = "~/Images/Products/" + product.Image,
                        CssClass = "productImage",
                        PostBackUrl = string.Format("~/Pages/Product.aspx?id={0}", product.Id)
                    };
                    Label lblName = new Label
                    {
                        Text = product.Name,
                        CssClass = "productName"
                    };
                    Label lblPrice = new Label
                    {
                        Text = "£ " + product.Price,
                        CssClass = "productPrice"
                    };

                    productPanel.Controls.Add(imageButton);
                    productPanel.Controls.Add(new Literal { Text = "<br/>" });
                    productPanel.Controls.Add(lblName);
                    productPanel.Controls.Add(new Literal { Text = "<br/>" });
                    productPanel.Controls.Add(lblPrice);

                    //Add dynamic controls to static control
                    pnlProducts.Controls.Add(productPanel);
                }
            }
             else
              pnlProducts.Controls.Add(new Literal { Text = "No products found!" });
        }
    }
}



and here is my Html index.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="GarageManager.index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Panel ID="pnlProducts" runat="server">
    </asp:Panel>
</asp:Content>

解决方案

In your sample code there is no such thing GarageManager.index, only GarageManager.Pages.Index!!!
Remember that Inherits attribute need a fully qualified name - the whole namespace before the class name!!!

<![CDATA[<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="GarageManager.Pages.Index" %>]]>


这篇关于分析器错误消息:此处不允许使用'GarageManager.index',因为它不扩展类'System.Web.UI.Page'。!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆