Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
Hi,

In my we form, I have a textbox where an integer can be placed and by clicking the button next to it, It should dynamically create that many textboxes as a table. The jQuery code for which is:



JavaScript
$("#ContentPlaceHolder1_LnkBtnNoofItems").click(function () {
        $(".white-table-view-block").removeClass("hide");
        $("#Table-id-Name").removeClass("hide");


        $("#Table-id-Name").each(function () {
            var NumbRow = $("#txtNoofItems").val();
            var htmlvar = '';
            for (i = 0; i < NumbRow; i++) {
                htmlvar += '';
                htmlvar += ' ';
                htmlvar += '<input type="text" id="item_number_input' + i + '" class="form-control" placeholder="Number" />';
                htmlvar += '<input type="text" id="item_des_input' + i + '" class="form-control" placeholder="Number" />';
                htmlvar += '<input type="text" id="item_quantity_input' + i + '" class="form-control" placeholder="Pieces" />';
                htmlvar += '<input type="text" id="item_cost_input' + i + '" class="form-control" placeholder="$" />';
                htmlvar += '<input type="text" id="item_total_input' + i + '" class="form-control" placeholder="$" />';
                htmlvar += '<a id="item_action_btn' + i + '" class="delet-icon"></a>';
                htmlvar += '';
            }

            $('.tbody-content').append(htmlvar);

            $(".delet-icon").click(function () {
                $(this).parents("tr").remove();
            });
        });
    });


The textbox and link button code is:
ASP.NET
<div class="col-md-4 col-lg-2">
                                <div class="number-of-item-block">
                                    <div class="row">
                                        <div class="col-md-12"><asp:label runat="server" ID="lblNoofItems" Text="No. of Item Rows"></div>
                                        <div class="col-md-12">
                                            <asp:TextBox runat="server" class="form-control" id="txtNoofItems" placeholder="#" > <asp:Linkbutton runat="server" ID="LnkBtnNoofItems" class="btn btn-dark-blue">
                                            <div class="row">
                                                <div class="col-md-6"></div>
                                                <div class="col-md-6"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>


Please help me how to solve this

What I have tried:

I have tried using jQuery but I need <asp:TextBox /> which is a server control so can not be created using client side code. Help me by providing server side code in C# on how to do this.
Posted
Updated 3-Nov-16 0:14am

 
Share this answer
 
v2
HI,

If your want touse jquery thn only:

1. Install firebug in your browser and then inspect the server control.
2. You will get an ID which is created for asp.net server control which can be used in jquery(client side).
3. Use that ID in jquery for manipulations.

Happy Coding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900