Read Only Checkbox(list) ?

?

/..

Hi all,

I'm working on a report display page that currently uses 5
checkboxlists with a total of 86 items to display values from 5
different tables in an Access database.

The page works fine now. On presenting it to the users they pointed
out that their users could change the values in the checkboxes and
then print them out, ultimately documenting false information.

I use these controls entirely to display boolean values from query
lookups. How can I make the checkboxlists read only?

I tried putting a checkboxlist in a web-forms panel control, and
setting the panel to read-only, like in older versions of Visual
Basic. While the checkboxes that were checked did display, and all
were read only, they were "grayed out", very low contrast and hard to
read.

I imagine that this could be done by inheriting the control class and
adding methods or properties to it, but that is beyond what I've ever
done, esp. in dot.net -- I'm kinda new to the subject, if not to
programming.

This has to be a FAQ, but I've been searching the web and don't find
anything close to answering the question.

I work mostly in C# (in ASP/ADO.Net)

Thanks,


/ts

--

exec rm -r /bin/laden*

##--------------------------------------------------##
"We are stardust, we are golden,
And we've got to get ourselves back to the Garden"
Joni Mitchell
##--------------------------------------------------##
 
C

Chaitanya Marvici

Here's an option for you to use.

Put the below code into your page. Then called the javascript function
enableFormElement on page load. Use the below function call:

enableFormElement( <form element>, <Is the element editable (true/false)> )

That will allow you to make checkbox's, radio button, textboxs, textareas,
etc, ALL either editable or not.

Now don't say I never gave you anything!

Enjoy

Chaitanya Marvici

Code below:

----------------------------------------------------------------------------
------------------------------------------------------------------

function enableFormElement( element, editable ) {

if( element.length && ( ( element.name + "" ) == "undefined" ) ) { //This is
used if a group of elements, all with the same name

for( var x = 0; x < element.length; x++ ) { //is sent to the function. It
will loop through and recursively

enableFormElement( element[x], editable ); //call this function to correctly
turn the readonly stuff off/on.

}

} else {

if( ( element.type != "hidden" ) && ( element.type != "button" ) && (
element.type != "image") ) {

var focusStr = element.onfocus + "";

var clickStr = element.onclick + "";

var changeStr = element.onchange + "";

var focusFunction, clickFunction, changeFunction;


focusStr = trim( focusStr.substring( focusStr.indexOf("{") + 1,
focusStr.lastIndexOf("}") ) );

clickStr = trim( clickStr.substring( clickStr.indexOf("{") + 1,
clickStr.lastIndexOf("}") ) );

if( element.type.indexOf( "select" ) >= 0 ) {

changeStr = trim( changeStr.substring( changeStr.indexOf("{") + 1,
changeStr.lastIndexOf("}") ) );

}


if( ! editable ) {

if( ( browserType == IE ) || ( browserType == Nav6 ) ) { element.readonly =
true; }


focusFunction = new Function( "e", "blurElement( this );\n" + focusStr )

clickFunction = new Function( "e", "blurElement( this );\n" + clickStr )


if( element.type == "radio" || element.type == "checkbox" ) {

element.checkedTemp = element.checked;

}


if( element.type.indexOf( "select" ) >= 0 ) {

changeFunction = new Function( "e", "resetElement( this );\n" + changeStr )

}

} else {

var strStart;


if( ( browserType == IE ) || ( browserType == Nav6 ) ) { element.readonly =
false; }


strStart = focusStr.lastIndexOf( "blurElement( this );" );

if( strStart != -1 ) { focusFunction = new Function( "e", focusStr.substr(
strStart + "blurElement( this );".length, focusStr.length ) ) }


strStart = clickStr.lastIndexOf( "blurElement( this );" );

if( strStart != -1 ) { clickFunction = new Function( "e", clickStr.substr(
strStart + "blurElement( this );".length, clickStr.length ) ) }


if( element.type.indexOf( "select" ) >= 0 ) {

strStart = changeStr.lastIndexOf( "resetElement( this );" );

if( strStart != -1 ) { changeFunction = new Function( "e",
changeStr.substr( strStart + "resetElement( this );".length,
changeStr.length ) ) }

}

}


if( typeof( focusFunction ) != "undefined" ) { element.onfocus =
focusFunction; }

if( typeof( clickFunction ) != "undefined" ) { element.onclick =
clickFunction; }

if( element.type.indexOf( "select" ) >= 0 ) {

if( typeof( changeFunction ) != "undefined" ) { element.onchange =
changeFunction; }

}

} // End check for form element type

}

}

function enableElements( f ) {

var numOfElements = f.length

var setFocus = false;

var proxyMarker = "Proxy";

for ( e = 0; e < numOfElements; e++ ) {

var visibleElement = f.elements[e];

var valueElement = f.elements[e];

if ( visibleElement.type=="checkbox") {

var visibleElementName = visibleElement.name;

if ( visibleElementName.indexOf(proxyMarker) >= 0 ) { // if proxy checkbox

var valueElementName = visibleElementName.substring( 0,
visibleElementName.indexOf(proxyMarker) );

valueElement = f.elements[ valueElementName ];

}

}

enableFormElement( visibleElement, isElementEditable( valueElement ) );

}

}

function blurElement( element ) {

if( element.type == "radio" || element.type == "checkbox" ) {

if( eval( "document." + element.form.name + "." + element.name +
".length" ) ) {

for( var x = 0; x < eval( "document." + element.form.name + "." +
element.name + ".length" ); x++ ) {

eval( "document." + element.form.name + "." + element.name + "[" + x +
"].checked = " + "document." + element.form.name + "." + element.name + "["
+ x + "].checkedTemp ? true : false;" );

}

} else {

element.checked = element.checkedTemp ? true : false;

}

}


if( element.type.indexOf( "select" ) >= -1 ) {

element.selectIndexTemp = element.selectedIndex;

}

element.blur();

}

function resetElement( element ) {

if( element.type.indexOf( "select" ) >= -1 ) {

element.selectedIndex = element.selectIndexTemp;

}

}
 
?

/..

By Tue, 22 Jul 2003 03:38:17 GMT, "Chaitanya Marvici"
<[email protected]>
decided to post
"Re: Read Only Checkbox(list) ?" to
microsoft.public.dotnet.framework.aspnet:
For those that are interested, there is a more readable brief tutorial
available at :

http://www.bitmap-productions.com/default.aspx?page=tutorials&tutorialid=8

Enjoy!

Chaitanya Marvici

Thanks a lot for the javascript code. I will look at it and learn a
lot, I'm sure. It didn't suit my client to use it, for their own
reasons, so I decided to go with images -- choice of images based on
bool value in db. I did a screen cap of the two states of a check
box and made very small bitmaps to use.

The code winds up fairly inelegant, but works like a charm. Nothing
elegant about this app anyway, it's based on accessing an Access
database that has been developed since at least 1997; dozens of
tables with similar columns, but slightly differing names, so I can't
cycle through and set values, but have to nominate them individually,
and so on. So goes the war.

Still there must be a FAQ dealing with read-only checkboxes or a
tutorial somewhere on how to extend the class with a new user-class??


/ts

--

exec rm -r /bin/laden*

##--------------------------------------------------##
"We are stardust, we are golden,
And we've got to get ourselves back to the Garden"
Joni Mitchell
##--------------------------------------------------##
 
Joined
Jul 1, 2009
Messages
1
Reaction score
0
ReadOnly CheckBoxList

It is actually very easy (not intuitive - but easy!).

in VB..

for each mylistitem as listitem in me.mycheckboxlist
mylistitem.Attributes.Add("onclick", "return false;")
next


That's all there is to it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top