ASPXページに2つのユーザーコントロールがあります。デフォルトでは、2番目のユーザーコントロールを無効にする必要があります。そのユーザーコントロールでは、テキストボックスが1つだけあります。だから私はこのようなページ読み込みイベントでコントロールを見つけます:
TextBox txtLocation = (TextBox)PI_CompLocationTree.FindControl("txtLocation");
txtLocation.Enabled = false;
しかし、私はtxtLocationをnullとして取得しています。ASPXページのコントロールをASCXコントロールから取得するにはどうすればよいですか?
私の更新されたコード..Aspxページで..
<%@ Register Src="~/UserControl/PI_CompLocationTree.ascx" TagName="PI_CompLocationTree"
TagPrefix="uc1" %>
<div id="Div2">
<div class="location">
<div class="usLocation">
<uc1:PI_CompLocationTree ID="PI_CompLocationTree1" runat="server"/>
</div>
</div>
</div>
ページの読み込み中...
PI_CompLocationTree PI_CompLocationTree = new PI_CompLocationTree();
protected void Page_Init(object sender, EventArgs e)
{
var userControl = (PI_CompLocationTree)this.FindControl("PI_CompLocationTree1");
userControl.EnabledTextBox = false;
}
ASCXページで...
<asp:TextBox ID="txtLocation" CssClass="fadded_text fadded_text_ctrl" Style="width: 260px;
float: left;" runat="server" Text=""></asp:TextBox>
ASCXコードビハインド...
public partial class PI_CompLocationTree : System.Web.UI.UserControl
{
public bool EnabledTextBox
{
get { return txtLoc.Enabled; }
set { txtLoc.Enabled = value; }
}
}