Rakesh Vishwakarma Ответов: 1

Показать div при загрузке страницы из кода C# позади


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.


Что я уже пробовал:

<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>

1 Ответов

Рейтинг:
0

ZurdoDev

Просто добавьте runat="server" к вашим divs, а затем вы можете получить к ним доступ из c#, если у них есть идентификатор.