How Get a Dynamic TextBox TextValue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhaimaya
    New Member
    • Feb 2013
    • 1

    How Get a Dynamic TextBox TextValue

    I have created 1 application that can create dyanmaic or multiple TextBox and now i need 4 how i can get a that created textbox value in a placeholder or a label...

    ASPX code

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Create_TextBox.WebForm1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            TextBox
    
            <asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
    
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="txtBox" ErrorMessage="Enter Numeric Value" 
                ValidationGroup="submit"></asp:RequiredFieldValidator>
            <br />
            <asp:Button ID="btnClickMe" runat="server" onclick="Button1_Click" 
                Text="Click Me" ValidationGroup="submit" />
                <asp:Panel ID="panel1" runat="server">
                </asp:Panel>    
        </div>
        <asp:Button ID="btnClickNow" runat="server" Visible="false" Text="Click Now" 
            onclick="btnClickNow_Click" />
        <asp:Panel ID="Panel2" runat="server">
        </asp:Panel>
        </form>
    </body>
    </html>
    ASPX.CS CODE

    Code:
      static int i = 0;
            TextBox tb;
            Label lb;
            public void box()
            {
                int val = Convert.ToInt32(txtBox.Text);
                for (i = 1; i <= val; i++)
                {
                    TextBox tb = new TextBox();
                    tb.ID = "textbox" + i.ToString();
                    tb.Attributes.Add("runat", "Server");
                    WebForm1 obj = new WebForm1();
                    obj.Controls.Add(tb);                
                }
            }        
            protected void Button1_Click(object sender, EventArgs e)
            {
                box();
                btnClickNow.Visible = true;
            }
            protected void btnClickNow_Click(object sender, EventArgs e)
            {
                WebForm1 obj = new WebForm1();
                string tvalue = string.Empty;
                string controlid = string.Empty;     
                for (i = 1; i <= obj.Controls.Count; i++)
                {
                    controlid = "textbox" + i.ToString();
                    TextBox tb = bj.FindControl(controlid) s TextBox;
                    if (tb != null)
                    {
                        Response.Write(tb.Text.ToString());
                    }
                }          
            }
        }
    Last edited by Meetee; Feb 11 '13, 08:24 AM. Reason: code tags [/CODE] added
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Check out this insight about how to use dynamic controls in ASP.NET.

    -Frinny

    Comment

    Working...