Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a web form in which i created multiple textboxes base on user requirement,
C#
<table  id="tbl1"  class="form-group">
           <tr><td class="col-sm-1">Code:</td><td ><asp:TextBox OnTextChanged="txtCode_TextChanged" AutoPostBack="true"  runat="server" ID="txtCode"></asp:TextBox></td><td class="col-sm-1">Fine:</td><td><asp:TextBox  runat="server" ID="txtFine"></asp:TextBox></td> <td> <a href="java<!-- no -->script:void(0);" id='anc_add' class="btn btn-green">Add Code</a></td>
      <td><a href="java<!-- no -->script:void(0);" id='anc_rem' class="btn btn-red ">Remove Code</a></td></tr>
           </table>
       <script>
           $(document).ready(function () {
               var cnt = 2;
               var cnt1 = 2;

               $("#anc_add").click(function () {
                   $('#tbl1 tr').last().after('<tr><td class="col-sm-1"> Code:' + cnt + '</td><td  class="col-sm-1"><asp:TextBox  runat="server" ID= "cnt"  ></asp:TextBox><td class="col-sm-1"> Fine:' + cnt1 + '</td><td  class="col-sm-1"><asp:TextBox  runat="server" ID= "cnt1"  ></asp:TextBox></td></tr>');
                   cnt++;
                   cnt1++;
               });

               $("#anc_rem").click(function () {
                   if ($('#tbl1 tr').size() > 1) {
                       $('#tbl1 tr:last-child').remove();
                   }
                   else {
                       alert('One row should be present in table');
                   }
               });
               var getval = $('input[data-type="number"]').val;
           });
</script>

there may be 2 or three rows with 4 or 6 textboxes,
i want to store these values in session ,and then call session in code behind ,and insert into database using for loop??does there is any solution?
Posted

1 solution

1. First Step :
Enable page method set to true, as shown here.

<asp:scriptmanager enablepagemethods="true" id="MainSM" runat="server" scriptmode="Release" loadscriptsbeforeui="true" xmlns:asp="#unknown">

2. Second Step :
use JavaScript function or AJAX alternately.
C#
function InitializeRequest(path) {
            // call server side method
            PageMethods.SetDownloadPath(path);
}


3. Make a method or service to request from function (Step 2)

C#
[System.Web.Services.WebMethod]
    public static string SetDownloadPath(string strpath)
    {
        Page objp = new Page();
        objp.Session["strDwnPath"] = strpath;
        return strpath;
    }
 
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