Deaktivieren von Benutzer-Steuerelement von code-behind?

Ich habe 2 Benutzer-Steuerelemente in eine ASPX-Seite. Standardmäßig wird der zweite Benutzer-Steuerelement deaktiviert werden soll. In diesem Benutzer-Steuerelement-ich bin nur ein Textfeld. Also ich finde die Steuerung im page load event wie diesem:

TextBox txtLocation = (TextBox)PI_CompLocationTree.FindControl("txtLocation");
txtLocation.Enabled = false;

Aber ich bin immer txtLocation als null. Wie bekomme ich das Steuerelement in der ASPX-Seite aus dem ASCX-Steuerelement?

Meine Aktualisierte Code..In der Aspx-Seite..

<%@ 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>

In Die Seite Laden...

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

In der ASCX-Seite...

<asp:TextBox ID="txtLocation" CssClass="fadded_text fadded_text_ctrl" Style="width: 260px;
float: left;" runat="server" Text=""></asp:TextBox>

In der ASCX-Code Hinter...

public partial class PI_CompLocationTree : System.Web.UI.UserControl
{
    public bool EnabledTextBox
    {
        get { return txtLoc.Enabled; }
        set { txtLoc.Enabled = value; }
    } 
}
  • Erste aspx ist ein page aber ascx ist ein Control mischen Sie keine dieser Definitionen
  • Ich bin nicht mischen..ich will das textbox-Steuerelement aus ascx und sollte ich deaktivieren, dass aus meiner ASPX-Code....
  • Nun deine Frage Sinn machen, wie diese: Du hast 2 regler in 1 aspx. Ändern wollte TextBox property Enabled die in 1-st Control von codebehind-2-nd Control. Wenn Sie möchten, ändern Sie diese property aus aspx codebehind nicht ascx-2-nd Control stellen Sie einfach die Eigenschaft, wie @Candie veröffentlicht vor. Schreiben Sie Ihre Frage zum understable.
InformationsquelleAutor RobinHood | 2012-08-29
Schreibe einen Kommentar