473,418 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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_Annotations.Attributes.Add( "onclick", "AlwaysOneChecked(
this.form )" );

<Client Script>
function AlwaysOneChecked( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.SearchContents.checked?1:0) +
(thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 1 )
{
thisForm.SearchContents.readonly =
(thisForm.SearchContents.checked?true:false)
thisForm.SearchProfiles.disabled =
(thisForm.SearchProfiles.checked?true:false)
thisForm.SearchAnnotations.disabled =
(thisForm.SearchAnnotations.checked?true:false)
}
else
{
thisForm.SearchContents.disabled = false;
thisForm.SearchProfiles.disabled = false;
thisForm.SearchAnnotations.disabled = false;
}
}
Nov 18 '05 #1
4 2457
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**************@tk2msftngp13.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_Annotations.Attributes.Add( "onclick", "AlwaysOneChecked(
this.form )" );

<Client Script>
function AlwaysOneChecked( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.SearchContents.checked?1:0) + (thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 1 )
{
thisForm.SearchContents.readonly =
(thisForm.SearchContents.checked?true:false)
thisForm.SearchProfiles.disabled =
(thisForm.SearchProfiles.checked?true:false)
thisForm.SearchAnnotations.disabled =
(thisForm.SearchAnnotations.checked?true:false)
}
else
{
thisForm.SearchContents.disabled = false;
thisForm.SearchProfiles.disabled = false;
thisForm.SearchAnnotations.disabled = 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*************@TK2MSFTNGP11.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**************@tk2msftngp13.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_Annotations.Attributes.Add( "onclick", "AlwaysOneChecked(
this.form )" );

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

(thisForm.SearchContents.checked?1:0) +
(thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 1 )
{
thisForm.SearchContents.readonly =
(thisForm.SearchContents.checked?true:false)
thisForm.SearchProfiles.disabled =
(thisForm.SearchProfiles.checked?true:false)
thisForm.SearchAnnotations.disabled =
(thisForm.SearchAnnotations.checked?true:false)
}
else
{
thisForm.SearchContents.disabled = false;
thisForm.SearchProfiles.disabled = false;
thisForm.SearchAnnotations.disabled = 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 AlwaysOneChecked( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.SearchContents.checked?1:0) +
(thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 0 )
window.event.returnValue = false;
else
window.event.returnValue = true;
}
"RodBillett" <No***@NoWhere.Com> wrote in message
news:uW**************@tk2msftngp13.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_Annotations.Attributes.Add( "onclick", "AlwaysOneChecked(
this.form )" );

<Client Script>
function AlwaysOneChecked( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.SearchContents.checked?1:0) + (thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 1 )
{
thisForm.SearchContents.readonly =
(thisForm.SearchContents.checked?true:false)
thisForm.SearchProfiles.disabled =
(thisForm.SearchProfiles.checked?true:false)
thisForm.SearchAnnotations.disabled =
(thisForm.SearchAnnotations.checked?true:false)
}
else
{
thisForm.SearchContents.disabled = false;
thisForm.SearchProfiles.disabled = false;
thisForm.SearchAnnotations.disabled = 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**************@tk2msftngp13.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_Annotations.Attributes.Add( "onclick", "AlwaysOneChecked(
this.form )" );

<Client Script>
function AlwaysOneChecked( thisForm )
{
var CheckedCount = CheckedCount = (thisForm.SearchContents.checked?1:0) + (thisForm.SearchProfiles.checked?1:0) +
(thisForm.SearchAnnotations.checked?1:0);

if ( CheckedCount == 1 )
{
thisForm.SearchContents.readonly =
(thisForm.SearchContents.checked?true:false)
thisForm.SearchProfiles.disabled =
(thisForm.SearchProfiles.checked?true:false)
thisForm.SearchAnnotations.disabled =
(thisForm.SearchAnnotations.checked?true:false)
}
else
{
thisForm.SearchContents.disabled = false;
thisForm.SearchProfiles.disabled = false;
thisForm.SearchAnnotations.disabled = false;
}
}

Nov 18 '05 #5

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

Similar topics

0
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...
0
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...
0
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...
5
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.......
1
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
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...
0
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...
10
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....
4
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.