Listbox selected values in modal popup

Hi experts,
I am using a modalpopup  extender to get data.I have three textboxes and a listbox.
What I am trying to do is,on save I am trying to save the values in textbox and get the selected values from listbox,but I am getting 0 from the listbox.
Maybe I am doing something silly,please help.

protected void btnAddUser_Onclick(object sender, EventArgs e)
        {
            bindFirmList();  //code to bind listbox with database fields
            popup.Show();
        }

protected void btnSave_Click(object sender, EventArgs e)
        {
            Firms frm = new Firms();
            frm.UserName = txtUserName.Text;
            frm.Name = txtName.Text;
            frm.Password = txtPassword.Text;

            int i = lstFirms.Items.Count;  //getting 0
            foreach (ListItem li in lstFirms.Items)  //not entering in loop
            {
                if (li.Selected)
                {
                    frm.FirmId = Convert.ToInt32(li.Value);
                    frm.SaveUser(frm);
                }
            }

           
            bindUserGrid();
            clearUserTextBoxes();
        }

private void bindFirmList()
        {
            Firms frm = new Firms();
            Dictionary<int, string> dictFirms = frm.getFirms();
            lstFirms.DataSource = dictFirms;
            lstFirms.DataTextField = "Value";
            lstFirms.DataValueField = "Key";
            lstFirms.DataBind();
        }


private void bindFirmList()
        {
            Firms frm = new Firms();
            Dictionary<int, string> dictFirms = frm.getFirms();
            lstFirms.DataSource = dictFirms;
            lstFirms.DataTextField = "Value";
            lstFirms.DataValueField = "Key";
            lstFirms.DataBind();
        }


LVL 8
Johny BravoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BurniePCommented:
Just to make sure.  Does your lstFirms have viewstate enabled?  Because your code looks fine to me.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Johny BravoAuthor Commented:
Oop I disabled the viewstate and somehow overlooked that part.
Thank you so much.I was scratching my head for long.
Thanks :)
BurniePCommented:
I'm glad I could help!

You can also thank me by accepting my comment :).

Johny BravoAuthor Commented:
:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.