Peyk Yazılım
Peyk Yazılım

Reputation: 71

Usercontrol .ascx variable access

What should be done to solve the problem of access?

Markup:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="Version_2.Themes.Anatema.Header" %>

<%= deneme %>

Code:

namespace Version_2.Themes.Anatema
{
    public partial class Header : UserControl
    {
        public string deneme = "asd";
    }
}

Error:

The name 'deneme' does not exist in the current context

Upvotes: 2

Views: 2096

Answers (1)

Nudier Mena
Nudier Mena

Reputation: 3274

Try this, it should work.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="user.ascx.cs" Inherits="user" %>
<asp:Label ID="Label1" runat="server">
<%=test%>
</asp:Label>

CODE BEHIND

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();

}
}

Upvotes: 1

Related Questions