2010-01-27 28 views
1

我動態填充label4.text。我希望能找回它在DBMS更新<標籤文本=「DYANMIC」>的動態填充後DYANMIC</label>無法檢索文本再次

<asp:Label ID="Label4" runat="server" Font-Bold="True" BackColor="#E3EAEB" 
Height="25px" Width="300px"><%=Application.Get("topic").ToString()%></asp:Label> 

在上述代碼我需要在<label>標記中插入text="<%=Application.Get("topic").ToString()%>,但由於語法錯誤而無法執行此操作,或者根本無法完成此操作。

我有一個linkbutton,通過點擊鏈接按鈕,我可以檢索標籤的文字。

<asp:LinkButton ID="LinkButton2" runat="server" Font-Size="Smaller" 
onclick="LinkButton2_Click">Post to Comment</asp:LinkButton> 

protected void LinkButton2_Click(object sender, EventArgs e) 
{ 
    string dumy=Label4.text.toString(); 
    // This is return a empty string.. 
} 

請讓我知道我錯了..還是有做... 因爲我動態填充label4.text任何其他方式..怎麼找回?

回答

0

試試這個在您的服務器端代碼

protected override void OnPreRender(System.EventArgs e) 
    { 
     base.OnPreRender(e); 
     if (!IsPostBack) 
     { 
      Label4.Text = Convert.ToString(Application.Get("topic")); //might be null? 
     } 
    } 

那麼你應該能夠拉從標籤上的文字在你的LinkBut​​ton因爲你擁有它(資本「文本」)

OR! !你可以只直接設置dumy字符串到Application.Get(「主題」)

如果你沒有服務器端代碼,我只想做後者的建議,並作出這樣的頁面上的標籤:

<label style="font-weight: bold; background: #e3eaeb; height: 25px; width: 300px;"><%=Application.Get("topic").ToString()%></label> 

(可能要考慮樣式,只是增加一個類=「mylabelstyle」屬性

0

您可以使用表達式生成器對於這一點,我們做這一切的時候。

看到here

所以你創建和註冊您的表達式生成器後,你會做這樣的事情

<asp:label runat="server" Text='<%$ AppText : "something" %>' />