[Mono-aspnet-list] CheckBoxList event and viewstate

Edgar edgarrc at gmail.com
Fri May 18 19:23:51 UTC 2012


Hi,

I'm trying to figure what is happening here. Tried to google everything
possible and I got many posts with the same problem with answers saying that
it was fixed in 2.6. There are some posts saying that it is working, others
that this problem persist. By the way, it does work on Windows IIS and if I
use DropDown instead of CheckBoxList it works too. The problem is the
following:

When I click on a checkbox item, the OnSelectedIndexChanged is never fired
up, but the postback is working. If I place a breakpoint in page_load and
another in SelectedIndexChanged, I can see a break on Page_Load every time I
click on CheckBoxList item. And, after the postback, all items that was
checked have it's state back to unchecked. So it is like the viewstate is
not being saved.


<%@ Page Language="C#" Inherits="testecheckbox.aaa" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:CheckBoxList ID="CheckBoxList1" runat="server"
EnableViewState="true" AutoPostBack="true"
        onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
        <asp:ListItem Value="1" Text="Option 1" />
        <asp:ListItem Value="2" Text="Option 2" />
    </asp:CheckBoxList>
    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace testecheckbox
{
        public partial class aaa : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               string a = "dddd";
            }
            protected void CheckBoxList1_SelectedIndexChanged(object sender,
EventArgs e)
            {
                string values = "";
               
                foreach (ListItem li in CheckBoxList1.Items)
                {
                    if (li.Selected == true)
                    {
                        values += li.Value;
                        values += ';';
                    }
                }
       
                Literal1.Text = values;
       
            }
               
        }
}

Thank you,

Edgar 

--
View this message in context: http://mono.1490590.n4.nabble.com/CheckBoxList-event-and-viewstate-tp4644970.html
Sent from the Mono - ASP.NET mailing list archive at Nabble.com.


More information about the Mono-aspnet-list mailing list