渲染控制错误。服务器块格式不正确

时间:2017-07-31 09:21:10

标签: c# asp.net user-controls

这是用户控制页面

static

控制器CS文件

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserInfoBoxControl.ascx.cs"
 Inherits="WebApplication3.UserInfoBoxControl" %>

<b>Information about <%@ this.UserName %></b><br /><br />

<%@ this.UserName %> is <%@ this.UserAge %> years old and lives in <%@ this.UserCountry %>

我要实现此目的的webform。

public partial class UserInfoBoxControl : 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)
    {


    }
}

获取错误 渲染控件出错:Myuserinfoboxcontrol 服务器块现在已经很好了。

我没有得到如何纠正

我想在我的webform上实现用户控件,但是我收到了这个错误。需要帮忙。感谢

1 个答案:

答案 0 :(得分:0)

我猜这个:

<b>Information about <%@ this.UserName %></b><br /><br />

<%@ this.UserName %> is <%@ this.UserAge %> years old and lives in <%@ 
this.UserCountry %>

应该是:

<b>Information about <%= this.UserName %></b><br /><br />

<%= this.UserName %> is <%= this.UserAge %> years old and lives in <%= 
this.UserCountry %>