Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i need help in c# code,Eg : I have 3 div on screen, Each contains controls for area code ,country code,Phone number and  desc. I want no of div to be rendered registered with application. Let say if i have registered 2 phone numbers with area code and desc then on page load i need to show 2 div sections to shoe two contact details on the screen similar if user has registered 3 phone numbers then there should be 3 div sections should be rendered also max limit of contact no registered is 3.


What I have tried:

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <div class="jumbotron">
        <div id="section1" class="phoneDetails">
            <label>
                <input type="checkbox" id="check1" value="1" /></label>
            <input type="text" name="Phone1" value="" />
            <input type="text" name="value" value="" />
        </div>
        <div id="section2" class="phoneDetails">
            <label>
                <input type="checkbox" id="check2" value="1" /></label>
            <input type="text" name="Phone1" value="" />
            <input type="text" name="value" value="" />
        </div>
        <div id="section3" class="phoneDetails">
            <label>
                <input type="checkbox" id="check3" value="1" /></label>
            <input type="text" name="Phone1" value="" />
            <input type="text" name="value" value="" />
        </div>
        <div id="section4" class="phoneDetails" style="display:none">
            <label> 
                <input type="checkbox" id="check4" value="1" /></label>
            <input type="text" name="Phone1" value="" />
            <input type="text" name="value" value="" />
        </div>
        <div id="button">
            <input id="btnAdd" type="button" value="+">
            <input id="btnRemove" type="button" value="-">
        </div>
    </div>

    <script>
        debugger;
        $(document).ready(function () {
            var sections = [];
            $('[id^="section"]').each(function () {
                sections = this;
            });
        });
        $("#btnAdd").click(function () {
            alert($('[id^="section"]:visible').length);
            $('#section2').insertAfter($('[id^="section"]:visible:last'));
        });
         $("#btnRemove").click(function () {
             $('input:checkbox[id^="check"]:checked').each(function () {
                 $(this).closest('div').remove();
             });
        });

    </script>
</asp:Content>
Posted
Updated 5-Feb-18 8:53am

1 solution

Just add runat="server" to your divs and then you can access them from c# as long as they have an id.
 
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