asp.net how to save checkbox satus when the update

2019-07-28 08:33发布

问题:

I have an update panel witch works in timer every 30 seconds.

the page contains many checkbox. when the update panel works, the check boxes return to their default statuses though some of them were selected before the update panel works.

any help please? There are the checkboxs:

<div ID="campaignDiv" runat="server" >
                            <ul>
                                <li>
                                    <span class="textDropdown">Text1</span>
                                    <input type="checkbox" id="1" value="1"/>
                                    <label for="1"></label>
                                </li>
                                 <li>
                                     <span class="textDropdown">Text1</span>
                                    <input type="checkbox" id="2" value="2"/>
                                    <label for="2"></label>
                                </li>
                                 <li>
                                     <span class="textDropdown">Text1</span>
                                    <input type="checkbox" id="3" value="3"/>
                                    <label for="3"></label>
                                </li>
                                 <li>
                                     <span class="textDropdown">Text1</span>
                                    <input type="checkbox" id="4" value="4"/>
                                    <label for="4"></label>
                                </li>
                            </ul>
                        </div>

回答1:

Add attribute runat="server" to your checkboxes. This will make them server-side controls and allow to use ASP.NET ViewState to save their states.

Note that you may have to change IDs of the checkboxes (and related for labels) currently yours are numeric like "1", you will have to make them alphanumeric e.g. "C1".