tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
1
ZUGRIFFE
266
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Kropotkin Kropotkin ist offline Mitglied Bronze
    Registriert seit
    Dec 2007
    Beiträge
    36
    Hallo.

    Jetzt könnt ich ausflippen. Ich mach ein ganz einfache Sach
    Ich will einem control im code ein control aus der site zuweisen.
    Das wollte ich mit findControl machen. Aber das bringtnull.

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
     
    <tr>
                <td style="width: 48px">
                    08.30-09.15</td>
                <td style="width: 136px">
                    <asp:TextBox ID=[B]"tbl1[/B]" runat="server" Height="16px" Width="61px" AutoPostBack="True"></asp:TextBox>
                    <asp:ImageButton ID="img1" runat="server" Height="16px" 
                        ImageUrl="~/App_Themes/Icons/icons/Edit.png" Width="16px" 
                        onclick="imgb_Click" />
                    <asp:DropDownList ID="ddll1" runat="server" Height="16px" Width="62px" 
                        Visible="False">
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>

    jetzt der 'Code'

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    [B]TextBox  myControl1 = FindControl("tbl1") as TextBox ; [/B]
            if (myControl1 != null)
            {
                Control myControl2 = myControl1.Parent;
                Response.Write("Parent of the text box is : " + myControl2.ID);
            }
            else
            {
                Response.Write("Control not found");
            }

    Ich weiss dass die Textbox da ist. Wieso findet der Code sie nicht?

    ciao und danke
     

  2. #2
    Kropotkin Kropotkin ist offline Mitglied Bronze
    Registriert seit
    Dec 2007
    Beiträge
    36
    Wow! so viele Antworten

    Aber ich hab die Antwort inzwischen selbst gefunden:
    Und ich will sie Euch nicht vorenthalten, damit nicht jeder drüber stolpert.
    wenn man die site in einer Masterpage hat (war bei mir der Fall) muss ich auch erst über
    das ContentPlaceHolder-Control gehen. Dh. ich muss das findcontrol im master-control stattfinden lassen


    in meinem Fall heisst das also:
    Code :
    1
    2
    
    ContentPlaceHolder c = Master.FindControl("MainContent") as ContentPlaceHolder;
     TextBox tbf = c.FindControl(sTbf) as TextBox;

    ciao
     

Ähnliche Themen

  1. Problem mit FindControl
    Von chrisfisch im Forum .NET Datenverwaltung
    Antworten: 0
    Letzter Beitrag: 27.07.10, 08:41
  2. Kann mir mal einer sagen wie man FindControl benutzt
    Von AppleSeed im Forum .NET Datenverwaltung
    Antworten: 8
    Letzter Beitrag: 01.10.07, 10:22
  3. Ich flipp aus Hair and Fur
    Von der_karl im Forum 3D Studio Max
    Antworten: 5
    Letzter Beitrag: 05.09.07, 01:38
  4. Wer hat noch Mac OS X 10.2.8?
    Von RobertGrund im Forum Mac OS
    Antworten: 2
    Letzter Beitrag: 07.11.05, 09:47
  5. Antworten: 14
    Letzter Beitrag: 08.12.03, 21:31