Hi,
I am populating the checkboxlist in (!IsPostBack) block of page load event
with some checked items.
After populating with checked items I am iterating through the items collection and applying color style for checked items.
The below method is called from !IsPostBack() -
public static void PopulateCheckBoxList(CheckBoxList checkBoxList, ArrayList nameValueList, ArrayList selectedItemsList)
-
{
-
checkBoxList.Items.Clear();
-
foreach (NameValueItem item in nameValueList)
-
{
-
ListItem li = new ListItem(item.ItemName, item.ItemValue.ToLower());
-
checkBoxList.Items.Add(li);
-
}
-
-
foreach (NameValueItem item in selectedItemsList)
-
{
-
checkBoxList.Items.FindByValue(item.ItemValue.ToLower()).Selected = true;
-
checkBoxList.Items.FindByValue(item.ItemValue.ToLower()).Attributes.Add("class", "selectedCheckBoxListItem");
-
}
-
}
The Issue: when the page is postedback, checkboxlist retaining its selections but losing its color style for selected items.
Please let me know why , the applied style attribute is not loaded in to viewstate.
Thanx & Regards,
only
3 5864 Frinavale 9,735
Recognized Expert Moderator Expert
Are you using Ajax?
Sometimes the styles aren't properly loaded after an asynchronous postback.
I'm not sure why the class wouldn't be loaded into ViewState....
-Frinny
Thanx Frinny.
I am not using AJAX.
Its fixed now.
I changed the code from: checkBoxList.It ems.FindByValue (item.ItemValue .ToLower()).Att ributes.Add("cl ass", "selectedCheckB oxListItem");
to: checkBoxList.It ems.FindByValue (item.ItemValue .ToLower()).Tex t = "<span class=\"selecte dCheckBoxListIt em\">" + checkBoxList.It ems.FindByValue (item.ItemValue .ToLower()).Tex t + "</span>";
The difference in rendered HTML in the baove two is,
in the first case, <span class="selected CheckBoxListIte m"> is added outside the label containing the listitem text. And this span is not postedback.
in the second case, <span class="selected CheckBoxListIte m"> is added insode the listitem label, but around the label text value. This span is postedback and there is no style loss.
Regards,
only
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bryce Budd |
last post by:
Hello All,
I've been a taker of information from newsgroups for a long time and thought
I'd finally make a contribution back to the community whose supported me
when I've needed it. After all before commercialization took over that was
the beauty of the Internet!
I've create a checkboxlist validator control...something MS should have done
originally in my opinion, but nonetheless here it is. It's a C# control,
sort of IE specific. ...
|
by: Robin Day |
last post by:
I run some code on the changed event of checkbox lists. Its quite simple,
nothing more than showing / hiding some other parts of the page.
Using Autopostback and Server side code works fine, but is far too slow,
especially if the users are on modems.
I need to quite simply, add some java code to the onclick event of the input
tags of a checkboxlist.
However... Attributes.Add adds the onclick attribute and code to the
outlying table that...
|
by: Shaul Feldman |
last post by:
Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmatically.
I add CheckBoxList's Items on the fly, something like
dim li as ListItem
li = new ListItem("title","value");
'' how to define here the CSS for List Item, not CheckBoxList?!?!?!
myCheckBoxList.Items(x).add(li);
|
by: Jack Black |
last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages...
Hi, all! I've been struggling with getting a dynamically-generated
CheckBoxList generated. I've finally been able to get the list
generated, but now there are two problems I haven't been able to
overcome:
1) ASP.Net is munging the checkbox ID/Names of the checkboxes: I give
it a name like "myCheckbox" and asp.net is creating the checkboxes
with the name...
|
by: bienwell |
last post by:
Hi,
I'm using the CheckBoxList control in ASP.NET for Web development. This
checkboxlist is bound by the database. If we have more items for this
checkbox list, it takes space on the page. I want to have vertical scroll
bar (like CheckedListBox in Window development) to save space. Can we do
that in ASP.NET ?
Please give me your suggestions ? Thanks in advance.
| |
by: ThunderMusic |
last post by:
Hi,
I have a CheckBoxList and I want to add some javascript code to each
CheckBox created by this CheckBoxList. I tried iterating through all items
of the list, all the controls, do a FindControl, et al. with no good result.
I would use the Control.Attribute.Add("OnClick", "some javascript code")
Does someone know a solution?
Thanks
|
by: Sully |
last post by:
Hi,
I am having a small problem generating an e-mail via an online form. I
am creating an e-mail using the MailMessage command and I know that you
have to do something special to render the values Checked with a
CheckBoxList, but I don't know what to do or how to do it. If anyone
could give me an example or send me to a link I would appreciate it.
Thanks in advance.
|
by: Jai |
last post by:
Hi,
Somebody please tell me how to bind(two way) a checkboxlist with
objectdatasource if the checkboxlist is inside a formview.....
Code of FormView is like this::---
<asp:FormView ID="FormView1" runat="server"
DataSourceID="ObjectDataSource1">
<EditItemTemplate>
|
by: Jai |
last post by:
Hi,
Somebody please tell me how to bind(two way) a checkboxlist with
objectdatasource if the checkboxlist is inside a formview.....
Code of FormView is like this::---
<asp:FormView ID="FormView1" runat="server"
DataSourceID="ObjectDataSource1">
<EditItemTemplate>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |