1

I have a UserControl that functions as a template for a FormView, But depending on whether it is in edit or insert mode, one of the TextBox controls needs to be disabled. I added a function to the UserControl

public bool IsInsert
{
    get { return txtUser.Enabled; }
    set { txtUser.Enabled = value; }
}

But I cannot get a reference of the UserControl in the parent's Page_Load event. I defined the control in the aspx code (not code-behind). I've tries using FindControl but I get an error Object reference not set to an instance of an object. Is this because the UserControl loads after the page? Is there another method of disabling the TextBox conditionally?

4

1 回答 1

1

这不是一个好习惯 -User Control应该单独决定这种东西......

但是如果需要这样做:

public void Page_Load(object sender, EventArgs e)
{
    InitYouUserControl();
}

更新:

你必须等到load event你的User Control被解雇。

并且要访问您的某些部分,User Control应该在其中定义一个属性。

于 2013-07-09T13:55:10.803 回答