繁体   English   中英

用户控件属性设置失败

[英]User control property fails on set

我在网络表单上有一个用户控件。 我在用户控件上具有受viewstate支持的公共属性。 在Web表单的代码背后,我尝试设置公共属性。 当我调试设置点后面的代码时,调试器从不带我进入设置器。 同样,永远不会设置公共属性的文本框的值。 为什么?

//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; }
    }
}

为什么不只是将属性包装控件? 这样,控件就可以为您管理视图状态:

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

这是我采用的方法,效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM