首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用<%= tag %>

使用<%= tag %>
EN

Stack Overflow用户
提问于 2012-02-29 17:13:49
回答 2查看 171关注 0票数 1

大家好,我在使用<%= %>标签中的属性时遇到了问题。由于某种原因,编译器不会提取<%= %>标记中的属性。正在使用的IDE是MVWD,我得到的错误是

代码语言:javascript
复制
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文件

代码语言:javascript
复制
<%@ 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文件

代码语言:javascript
复制
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)
    {

    }


 }
EN

回答 2

Stack Overflow用户

发布于 2012-02-29 17:27:15

我认为你可以把字段放到文本控件中,aspx确实会看起来很难看。类似这样的东西(我使用的是资源,但应该是类似的)

代码语言:javascript
复制
<asp:Literal ID="Literal6" runat="server" Text="<%$ Resources:General, lblFunctie %>"></asp:Literal>
票数 1
EN

Stack Overflow用户

发布于 2012-02-29 17:15:56

我觉得你只需要去掉“this”前缀..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9496316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档