大家好,我在使用<%= %>标签中的属性时遇到了问题。由于某种原因,编译器不会提取<%= %>标记中的属性。正在使用的IDE是MVWD,我得到的错误是
Error 2 'ASP.webusercontrol1_ascx' does not contain a definition for
'UserName' and no extension method 'UserName' accepting a first argument of type
'ASP.webusercontrol1_ascx' could be found (are you missing a using directive or an
assembly reference?) c:\Users\jonny\Documents\Visual Studio 2010\Projects\WebApplication8\WebApplication8\WebUserControl1.ascx 2 36 WebApplication8我的WebUserControl1.ascx文件
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs"
Inherits="WebApplication8.WebUserControl1" %>
<b>Information about </b> <%= this.UserName%>
<br /><br />
<%= this.UserName %> is <%= this.UserAge %> years old and lives in <%= this.UserCountry %>这是我的Webusercontrol1.ascx.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication8
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
private string userName;
private int userAge;
private string userCountry;
public string UserName
{
get { return userName; }
set { userName = value; }
}
public int UserAge
{
get { return userAge; }
set { userAge = value; }
}
public string UserCountry
{
get { return userCountry; }
set { userCountry = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}发布于 2012-02-29 17:27:15
我认为你可以把字段放到文本控件中,aspx确实会看起来很难看。类似这样的东西(我使用的是资源,但应该是类似的)
<asp:Literal ID="Literal6" runat="server" Text="<%$ Resources:General, lblFunctie %>"></asp:Literal>发布于 2012-02-29 17:15:56
我觉得你只需要去掉“this”前缀..。
https://stackoverflow.com/questions/9496316
复制相似问题