ASp.net How to get textbox values generated byJavascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandesh Daddi

    #1

    ASp.net How to get textbox values generated byJavascript



    You can use following code to get it work


    <%@ Page Language="C#" AutoEventWireup ="true"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>

    <script type="text/javascript" >

    function createTextBox(e vent)
    {

    //Get the reference of DIV where we want to show textboxes
    var dv = document.getEle mentById("dvTex tBoxes");

    //Create the Textbox and append that to DIV.
    var tx = document.create Element("INPUT" );
    tx.name = "txt";
    tx.value= "1";
    dv.appendChild( tx);
    }
    </script>


    <script type="text/C#" runat="server" >

    protected void Page_Load(objec t sender, EventArgs e)
    {
    try
    {
    if (Page.IsPostBac k)
    {
    String strValues = Request.Form["txt"];

    String[] strV = strValues.Split (',');

    for (int i = 0; i < strV.Length; i++)
    {
    lblError.Text += strV[i].ToString() + "\n";
    }
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <input type="button" id="btnAddText " value="Add text" onclick="create TextBox(event)" />
    <div id="dvTextBoxes ">
    </div>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit"/>

    <asp:Label ID="lblError" runat="server" ForeColor="RED" ></asp:Label>
    </div>
    </form>
    </body>
    </html>


    Reply me if you want some thing else


    Thank you
    Saandesh Daddi


Working...