0
function CountrySelect(uniqueID) {

        var dialog_buttons = {};
        dialog_buttons['Save'] = function () { __doPostBack('chkcountries', ''); }

        $(document).ready(function () {
            $(function () {
                var dlg = $("#dialog").dialog({
                    maxWidth: 400,
                    maxHeight: 500,
                    width: 400,
                    height: 500,

                    autoOpen: false,
                    modal: true,
                    buttons:dialog_buttons,
                    title:"Country Selection dialog",
                    close: CloseFunction
                    ,
                    show: {
                        effect: "Clip",
                        duration: 1000
                    },
                    hide: {
                        effect: "fade",
                        duration: 1000
                    }
                });

and markup for div with id dialog is

<div id="dialog" style="display:none">
        <p>Select Countries</p>
        <p>
            <asp:CheckBoxList ID="chkcountries"  runat="server">                   
            </asp:CheckBoxList>
        </p>

and in cs file code is

 foreach (ListItem val in chkcountries.Items)
   {
       if (val.Selected == true)
        {

        }
   }

problem is on postback it says no item is checked. why

i am not able to get the checked state of checkbox list items.

val.selected=false 

always

BR BHARDWAJ
  • 399
  • 2
  • 17

2 Answers2

0

Unfortunately, I can't create comments yet, so I have to do this in an answer. We need to see the code for populating "chkcountries". I think you are doing it in your page load event and not checking if you're in a postback when you do that. So every time the page loads (including postbacks) your checkboxes get reloaded, thus none of them are checked.

Please post your page_load code or wherever you are loading your checkbox list control.

Ray Phillips
  • 95
  • 1
  • 7
0

Add these property in your checkbox

<asp:CheckBoxList ID="chkcountries" runat="server" EnableViewState="true">
</asp:CheckBoxList>

Setting EnableViewState to true will preserve the state of control on postback

Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200
  • viewstate is enabled for all controls on page. moreover when i postback througn asp.net controls then it works good. i think theres something i am missing with this mannaul postback with Javascript. – BR BHARDWAJ Apr 17 '15 at 05:52
  • this is how i am doing postback dialog_buttons['Save'] = function () { __doPostBack('chkcountries', ''); } – BR BHARDWAJ Apr 17 '15 at 05:53
  • Try adding `runat` attribute to your `dialog_button['Save']` – Guruprasad J Rao Apr 17 '15 at 06:03
  • i dont think jquery ui dialoge buttons supports runat="server" attribute Can you post a workin snippet? – BR BHARDWAJ Apr 17 '15 at 06:10
  • Just check **[this link](http://stackoverflow.com/questions/757232/jquery-ui-dialog-with-asp-net-button-postback)** you might get some idea.. :) – Guruprasad J Rao Apr 17 '15 at 06:13