2013-05-16 28 views
0

我在webform上有一個用戶控件。我有用戶控件上的viewstate支持的公共屬性。在webform的代碼隱藏中,我嘗試設置公共屬性。當我通過代碼背後的代碼進行調試時,調試器從不將我帶到setter。同樣,公共屬性的文本框的值永遠不會被設置。爲什麼?用戶控件屬性在集合上失敗

//aspx page with reference to user control on a telerik tab/page view 
<telerik:RadPageView ID="radpvCommunication" runat="server"> 
    <uc:Communication ID="Communication1" runat="server" /> 
</telerik:RadPageView> 

//Webform method to set user control public property 
private void SetCommunicationControlText() 
{ 
    Communication1.SubjectTextBoxText = "This is a test set from organization"; 
} 

//user control code 
public partial class CommunicationUserControl : UserControl 
{ 
    public string SubjectTextBoxText 
    { 
     get { return ViewState["SubjectTextBoxText"].ToString(); } 
     set { ViewState["SubjectTextBoxText"] = value; } 
    } 
} 
+0

當您在'SetCommunicationControlText'上放置斷點並進入該賦值時會發生什麼?要進入屬性,請參閱此stackoverflow答案:http://stackoverflow.com/a/4873299/507793 – Matthew

+0

它從來沒有介入。它跨越了下一行。就像我打F10,而不是F11。 – webapparchitect

+0

你從哪裏調用'SetCommunicationControlText'方法? – Win

回答

1

爲什麼不只是讓屬性包裹控件?這樣,控制管理視圖狀態爲您:

public string SubjectTextBoxText 
{ 
    get { return TextBox1.Text; } 
    set { Textbox1.Text = value; } 
} 

這是我採取的方法,它的工程很好。

+0

好吧,它的工作。問題解決了。我如何分裂你和馬修之間的接受? – webapparchitect