Autor Beitrag
Vitalic
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68



BeitragVerfasst: Do 18.11.10 18:49 
Hallo, ich kann inzwischen Textboxen dynamisch erstellen.
Weiß aber nicht, wie ich die TextBox anschließend auf Inhalt prüfen kann.
Wenn ich auf Create gehe, dann erstellt er mir die gewünschte Anzahl an Textboxen, die ich über DropDownList1 angebe.
Nun möchte ich die einzelnen Textboxen auf Inhalt prüfen, wenn ich auf Save klicke.


Folgendes habe ich bereits erstellt:


ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Value="1" Text="1" Selected="True" />
                    <asp:ListItem Value="2" Text="2" />
                    <asp:ListItem Value="3" Text="3" />
                    <asp:ListItem Value="4" Text="4" />
                    <asp:ListItem Value="5" Text="5" />
                    <asp:ListItem Value="6" Text="6" />
                </asp:DropDownList>

                <asp:Button ID="ButtonCreate" runat="server" Text="Create" Width="100px" 
                    onclick="ButtonCreate_Click" />

                <asp:Button ID="ButtonSave" runat="server" Text="Save" Width="100px" 
                    onclick="ButtonSave_Click" />


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
     private void AccessPoint(int value)
        {
            value *= 2;

            for (int i = 0; i < value; i++)
            {
                TextBox t = new TextBox();
                t.ID = "ap_" + i;
                this.PlaceHolder1.Controls.Add(t);
            }
        }

        protected void ButtonCreate_Click(object sender, EventArgs e)
        {
            AccessPoint(Convert.ToInt16(DropDownList1.Text));
        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
        }



Ich habe gelesen, dass man das mit PostBack machen kann, jedoch hab ich keine Erfahrung damit.

So funktioniert das bei mir nicht, was habe ich da falsch gemacht?

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
protected void ButtonSave_Click(object sender, EventArgs e)
        {
            if ((PreviousPage != null) && (PreviousPage.IsCrossPagePostBack))
            {
                Page previousPage = PreviousPage;
                TextBox ap = (TextBox)previousPage.FindControl("ap_0");
                statusText.Text = ap.Text;
            }
        }



Danke für die Mühe!

Gruß, Vitalic