2014-10-27 68 views
1

我有一个简单的.ascx页面,看起来像这样:在代码中访问的变量用于ASCX背后

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

<div> 
    <h1>Data Lookup</h1> 

    <p><%= d1 %></p> 
</div> 

页面背后的代码看起来是这样,和DoDataLookup方法被调用在运行此开始页:

public partial class ctl_dataLookup : BaseDomainControl 
{ 

     private string d1; 
     public string D1 { get { return d1; } } 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      this.Visible = false; 
      this.DataBind(); 
     } 

     public void DoDataLookup(int DomainId, string DomainName) 
     { 
      this.Visible = true; 

      d1 = "TEST DOMAIN"; 
     } 


} 

然而,<%= D1%>总是最终看起来像这样当在呈现页面(System.Web.UI.WebControls.Label):

enter image description here

我已经看过无数堆栈溢出的例子,但它看起来好像我做的一切都是正确的...有什么明显的原因,为什么会发生这种情况?

回答

2

尝试使用D1,而不是私有的d1变量。 希望这个作品。

谢谢

+0

Doh ...谢谢JayHach! – Matt 2014-10-27 21:47:10