. .(您是否缺少using指令或汇编引用?)
本文关键字:汇编 引用 指令 using 是否 | 更新日期: 2023-09-27 18:04:57
请帮我解决以下问题。我被难住了。我有一个名为"one"的文件夹,里面只有2个文件。第一个是DemonstrationOne.aspx:
<%@ Page Language="C#" Title="Demo" CodeBehind="DemonstrationOne.aspx.cs" AutoEventWireup="true" Async="true" %>
<head runat="server">
<title><%: Title %></title>
</head>
<body>
<form id="sayHello" runat="server">
<div>
<asp:Button ID="doSomething" OnClick="DemonstrateMe" Text="Show Label" runat="server"></asp:Button>
<asp:PlaceHolder runat="server" ID="showLiteral" Visible="false">
<p><asp:Literal ID="HelloWorldLabel" runat="server"></asp:Literal></p></asp:PlaceHolder>
</div>
</form>
</body>
第二个当然是demonstrationone。asp .cs:
using System;
using System.Web.UI;
namespace OneDemonstration
{
public partial class DemonstrateMe
{
protected global::System.Web.UI.WebControls.Literal HelloWorldLabel;
protected global::System.Web.UI.WebControls.PlaceHolder showLiteral;
}
public partial class DemonstrateMe : Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void sHowHelloWorldLabel(object sender, EventArgs e)
{
showLiteral.Visible = true;
HelloWorldLabel.Text = "Hello World!";
}
}
}
我去visual studio,点击文件>打开>网站(我不从向导自动生成它),然后点击运行。这给了我错误消息:
'ASP.demonstrationone_aspx'不包含'DemonstrateMe'的定义,也没有扩展方法'DemonstrateMe'接受a可以找到'ASP.demonstrationone_aspx'类型的第一个参数您缺少using指令或程序集引用吗?)
我想指出,我是一个初学者,甚至在aspx web表单(没有自动生成的向导)中显示"Hello World"标签都有问题。我认为它只会工作,如果它是由Visual studio生成?
请帮。
ok !我花了很长时间重新阅读我做错了什么,显然"web应用程序"answers"网站"是不同的东西!谁想到了!这就是解决方案。
首先添加一个Web。配置文件,其中包含以下代码:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
</system.web>
</configuration>
在主。aspx文件中去掉CodeBehind
,增加CodeFile
和Inherits
,并分别填写。在我的例子中:
<%@ Page Language="C#" Title="Demo" CodeFile="DemonstrationOne.aspx.cs" Inherits="DemonstrationOne.Demo" AutoEventWireup="true" Async="true" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><%: Title %></title>
</head>
<body>
<form id="sayHello" runat="server">
<asp:Button runat="server" OnClick="ShowLabel" Text="Show Label" /><br/>
<asp:PlaceHolder runat="server" ID="showLiteral" Visible="false">
<p><asp:Literal ID="HelloWorldLabel" runat="server"></asp:Literal></p>
</asp:PlaceHolder>
</form>
</body>
</html>
最后但并非最不重要的是添加一些using
指令并删除多余的变量声明。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DemonstrationOne
{
public partial class Demo : Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void ShowLabel(object sender, EventArgs e)
{
showLiteral.Visible = true;
HelloWorldLabel.Text = "Work damnitt aarrgghh!!";
}
}
}
应该可以。现在,去买个新键盘吧。你现在的键盘可能因为经常用你的额头砸按键而有粘键。