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;
}
} 4 2376
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; } }
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; } }
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; } }
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; } }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
|
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...
|
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...
|
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 ...
<%
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |