473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Always One checkbox checked

I have a situation where I have 3 checkboxes - and at least 1 needs to be
selected at all times...

I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after a
postback. but when I have one checkbox and it is disabled, then when I
postback, ALL checkboxes get the unchecked value.

Thanks
Rod

on the server, when I create the checkboxes, i add the following attribute
to all. and they are defaulted to all 'Checked=true"

SearchWhat_Anno tations.Attribu tes.Add( "onclick", "AlwaysOneCheck ed(
this.form )" );

<Client Script>
function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.Searc hContents.check ed?1:0) +
(thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 1 )
{
thisForm.Search Contents.readon ly =
(thisForm.Searc hContents.check ed?true:false)
thisForm.Search Profiles.disabl ed =
(thisForm.Searc hProfiles.check ed?true:false)
thisForm.Search Annotations.dis abled =
(thisForm.Searc hAnnotations.ch ecked?true:fals e)
}
else
{
thisForm.Search Contents.disabl ed = false;
thisForm.Search Profiles.disabl ed = false;
thisForm.Search Annotations.dis abled = false;
}
}
Nov 18 '05 #1
4 2476
Changes made to the state of the objects on the client via JavaScript do not
affect ViewState, which is what ASP.Net uses to keep track of the state of
the Controls on the client. In other words, when you make a change via
JavaScript, it is not recorded in ViewState. When the next PostBack occurs,
the ViewStyate is used on the server to put the objects back into the state
they were in according to ViewState.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"RodBillett " <No***@NoWhere. Com> wrote in message
news:uW******** ******@tk2msftn gp13.phx.gbl...
I have a situation where I have 3 checkboxes - and at least 1 needs to be
selected at all times...

I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after a postback. but when I have one checkbox and it is disabled, then when I
postback, ALL checkboxes get the unchecked value.

Thanks
Rod

on the server, when I create the checkboxes, i add the following attribute
to all. and they are defaulted to all 'Checked=true"

SearchWhat_Anno tations.Attribu tes.Add( "onclick", "AlwaysOneCheck ed(
this.form )" );

<Client Script>
function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.Searc hContents.check ed?1:0) + (thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 1 )
{
thisForm.Search Contents.readon ly =
(thisForm.Searc hContents.check ed?true:false)
thisForm.Search Profiles.disabl ed =
(thisForm.Searc hProfiles.check ed?true:false)
thisForm.Search Annotations.dis abled =
(thisForm.Searc hAnnotations.ch ecked?true:fals e)
}
else
{
thisForm.Search Contents.disabl ed = false;
thisForm.Search Profiles.disabl ed = false;
thisForm.Search Annotations.dis abled = false;
}
}

Nov 18 '05 #2
Well, that is only partially true.

Lets say that a page rendered to the client has Checkbox 1 and 2 are Checked
(So in viewstate, they are both remembered as 'checked'). Then I click
Checkbox2 to uncheck it. The JScript then disables checkbox1 - but it still
appears checked. I now force another postback! Both on the server during
processing and in the re-rendered page at the client, it has a value of
unchecked for checkbox1!

So it didnt really use the viewstate it had - It appears more like since the
control is disabled, all the server side framework processing 'forgets about
the poor little control!'

Rod

"Kevin Spencer" <ke***@takempis .com> wrote in message
news:en******** *****@TK2MSFTNG P11.phx.gbl...
Changes made to the state of the objects on the client via JavaScript do not affect ViewState, which is what ASP.Net uses to keep track of the state of
the Controls on the client. In other words, when you make a change via
JavaScript, it is not recorded in ViewState. When the next PostBack occurs, the ViewStyate is used on the server to put the objects back into the state they were in according to ViewState.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"RodBillett " <No***@NoWhere. Com> wrote in message
news:uW******** ******@tk2msftn gp13.phx.gbl...
I have a situation where I have 3 checkboxes - and at least 1 needs to be selected at all times...

I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after
a
postback. but when I have one checkbox and it is disabled, then when I
postback, ALL checkboxes get the unchecked value.

Thanks
Rod

on the server, when I create the checkboxes, i add the following
attribute to all. and they are defaulted to all 'Checked=true"

SearchWhat_Anno tations.Attribu tes.Add( "onclick", "AlwaysOneCheck ed(
this.form )" );

<Client Script>
function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount =

(thisForm.Searc hContents.check ed?1:0) +
(thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 1 )
{
thisForm.Search Contents.readon ly =
(thisForm.Searc hContents.check ed?true:false)
thisForm.Search Profiles.disabl ed =
(thisForm.Searc hProfiles.check ed?true:false)
thisForm.Search Annotations.dis abled =
(thisForm.Searc hAnnotations.ch ecked?true:fals e)
}
else
{
thisForm.Search Contents.disabl ed = false;
thisForm.Search Profiles.disabl ed = false;
thisForm.Search Annotations.dis abled = false;
}
}


Nov 18 '05 #3
OK - I can get partway to where i want to by modifying the script to cancel
the click event (as listed below). But that does not render the checkbox in
'disabled' mode. Apparently, this appears very confusing to non technical
people - LIKE USERS - therefore, I still need to render the checkbox -
disabled!! (Anyone else have the problem with marketing people wanting
windows aplications on the Web?)

Thanks in Advance!
Rod

function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.Searc hContents.check ed?1:0) +
(thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 0 )
window.event.re turnValue = false;
else
window.event.re turnValue = true;
}
"RodBillett " <No***@NoWhere. Com> wrote in message
news:uW******** ******@tk2msftn gp13.phx.gbl...
I have a situation where I have 3 checkboxes - and at least 1 needs to be
selected at all times...

I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after a postback. but when I have one checkbox and it is disabled, then when I
postback, ALL checkboxes get the unchecked value.

Thanks
Rod

on the server, when I create the checkboxes, i add the following attribute
to all. and they are defaulted to all 'Checked=true"

SearchWhat_Anno tations.Attribu tes.Add( "onclick", "AlwaysOneCheck ed(
this.form )" );

<Client Script>
function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.Searc hContents.check ed?1:0) + (thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 1 )
{
thisForm.Search Contents.readon ly =
(thisForm.Searc hContents.check ed?true:false)
thisForm.Search Profiles.disabl ed =
(thisForm.Searc hProfiles.check ed?true:false)
thisForm.Search Annotations.dis abled =
(thisForm.Searc hAnnotations.ch ecked?true:fals e)
}
else
{
thisForm.Search Contents.disabl ed = false;
thisForm.Search Profiles.disabl ed = false;
thisForm.Search Annotations.dis abled = false;
}
}

Nov 18 '05 #4
the browser will not postback a disabled or unchecked checkbox, so to the
server it looks exactly the same. if you want to disable a checked checkbox,
then you must enable it before submit, or store the value in a hidden field.

-- bruce (sqlwork.com)
"RodBillett " <No***@NoWhere. Com> wrote in message
news:uW******** ******@tk2msftn gp13.phx.gbl...
I have a situation where I have 3 checkboxes - and at least 1 needs to be
selected at all times...

I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after a postback. but when I have one checkbox and it is disabled, then when I
postback, ALL checkboxes get the unchecked value.

Thanks
Rod

on the server, when I create the checkboxes, i add the following attribute
to all. and they are defaulted to all 'Checked=true"

SearchWhat_Anno tations.Attribu tes.Add( "onclick", "AlwaysOneCheck ed(
this.form )" );

<Client Script>
function AlwaysOneChecke d( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.Searc hContents.check ed?1:0) + (thisForm.Searc hProfiles.check ed?1:0) +
(thisForm.Searc hAnnotations.ch ecked?1:0);

if ( CheckedCount == 1 )
{
thisForm.Search Contents.readon ly =
(thisForm.Searc hContents.check ed?true:false)
thisForm.Search Profiles.disabl ed =
(thisForm.Searc hProfiles.check ed?true:false)
thisForm.Search Annotations.dis abled =
(thisForm.Searc hAnnotations.ch ecked?true:fals e)
}
else
{
thisForm.Search Contents.disabl ed = false;
thisForm.Search Profiles.disabl ed = false;
thisForm.Search Annotations.dis abled = false;
}
}

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2133
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
0
1576
by: Zürcher See | last post by:
I have a checkbox as sample, I have to create n-checkbox like that one in a webform, so I have extended the CheckBox class and wrote a public clone method that use the protected MemberwiseClone method. If I look the MemberwiseClone method definiton I find the following phrase: " Return Value A shallow copy of the current Object.
0
1860
by: mehul | last post by:
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip in ASP.NET Hi, I am trying to develop an ASP.NET application. I am using TabStrip (which is part of IE WebControls). Inside a tab I have a datagrid defined as follows:
5
3673
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.... 2. after population there should be validation in checkboxlist..... that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form....... these 2 steps should be...
1
6588
by: Eric via .NET 247 | last post by:
Hello, I'm dynamicly filling a table with checkboxes, doing this: ... CheckBox chkBox = new CheckBox(); chkBox.ID = "chk" + i.ToString(); chkBox.AutoPostBack=true; ...
1
3781
by: VB Programmer | last post by:
Simple: I have a datalist that is holding a bunch of job opportunities. Beside each opp (in the item template) there's a checkbox that says "apply". After the datalist there's a button that say's "process". I want to LOOP through each datalist entry and see if the user checked the check box. Simple. I wrote the code, but the checked value is ALWAYS False. Any ideas? Here's the code...
0
2274
by: peter.bittner | last post by:
I have developed a Windows application in Visual Studio .NET 2003 and created a Setup project for it. In the File System Editor I have added a shortcut to the User's Desktop folder to point to the application once it has been installed. I have added a condition to the User's Desktop named "DESKTOPSHORTCUT" (I have used several names, this is just the latest). In the User interface, I have added a screen with a checkbox that asks the user...
10
5209
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
4
4440
by: Charlotte | last post by:
Hi, I have a problem with a ASP-script, can somewone help me ? here is what I've got: mypage.asp : .... code ... <%
0
9673
marktang
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...
0
10448
Oralloy
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...
0
10217
jinu1996
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...
0
10003
tracyyun
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...
0
6784
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();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.