如何解决访问问题?
标记:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="Version_2.Themes.Anatema.Header" %>
<%= deneme %>
代码:
namespace Version_2.Themes.Anatema
{
public partial class Header : UserControl
{
public string deneme = "asd";
}
}
错误:
当前上下文中不存在名称'deneme'
答案 0 :(得分:1)
试试这个,它应该有效。
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="user.ascx.cs" Inherits="user" %>
<asp:Label ID="Label1" runat="server">
<%=test%>
</asp:Label>
代码背后
using System;
public partial class user : System.Web.UI.UserControl{
public string test = "This is a test";
protected void Page_Load(object sender, EventArgs e){
this.DataBind();
}
}