2014-10-27 65 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