Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking a check box?

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
US
-- posted to asp also --

I have a web app that is showing a true/false in a checkbox. The form it is being displayed in is for all intents an purposes read only. I.E. I don't want the user to think they can change or edit anything on this page.

What I would like to do is in essence make the checkbox behave like a locked checkbox in a VB application... Any ideas.

Rob

PS I am thinking about just displaying an image of a check or X depending on enabled or not at the moment, but a check box would be easier to implement (maybe)

 
Set the Checkboxes enabled property to false. The check box then becomes greyed out and the user can't touch it.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Another option (but it'll cost a postback) is if you write this sort of sub:

Public Sub Check_Click() handles Check.Clicked
'have some variable specifying state
If state = "ReadOnly" Then
Check.Clicked = Not Check.Clicked
End If
End Sub

Here's what it does:
If the user clicks it, and its in a read-only sort of state, then the page posts back but maintains the value it had.

The only difference between this and Mark's suggestion is that it takes a postback, but the box isn't greyed out (it stays white)

hth

D'Arcy
 
D' Arcy..

Thanks I will try that.. I did try Marks Enabled but that didn't work..

Again


Thanks

Rob
 
I don't really like Jacks suggestion actually. The user will likely try to change the value multiple times causeing multiple postbacks (why? cause users are stupid) which is an unnessacary (sp?) strain on your server and resources.

You can change the check box Enabled value right in the design view if you want. Your code may not be working properly if the code doesn't get run for some reason. (its under an event that doesn't get fired, or inside a postback check)

Some of my opinion for what it was worth

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
oh believe me, I'm not keen on my idea either. We were in a situation where we didn't want to grey out any of the user interface (textboxes were read only with no borders if the user wasn't supposed to modify the data instead of just disabled with a grey background...it looked alot better, and its what the customer wanted). So we came up with that solution. It will work, but as Mark mentioned it can have an adverse affect on the web server if enough *ahem* "challanged" users try to click it too many times.

D'Arcy
 
How about an onClick event that brings up an alert that says DON'T TOUCH ME!

P-)
 
How about adding a javascript function to che client side checkbox onclick event...
<CODE TYPE=c#>
checkbox.Attributes.Add(&quot;onclick&quot;,&quot;Javascript:CancelAction();&quot;);
</CODE>

<CODE TYPE=JScript>
<script language=&quot;javascript&quot;>
function CancelAction()
{
event.returnValue = false;
}
</script>
</CODE>

I use this for a read only check box on a couple of pages in my current development, although it is an internal one and I can guarantee that JavaScript is enabled on the browser...

Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
Rhys, Mark..

Rhys.. Thanks that looks great i will give that a go. This is also for an internal app.. and I can be 100% certain of the browser. So looks like it should do the job.

Mark, I did find the enabled=false syntax. it was just to add a dissabled attribute to the tag.. The problem with this however is that the control is greyed... Picky, picky picky... oh well thanks anyway it was a good try. I also agree that doing this server side is not an option. Too much traffic.

I did have a msgbox say something less plesant than your last suggestion, but we decided it was politicly incorrect. Maybe your wording would work better :)

Thanks all

Rob
 
Let us know of further issues, or if all solved, it's just nice to know. :)

Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
The final answer.....

a checkbox has a ReadOnly attribute... This works just like the good old locked=true in VB. Not greyed but the user can't change it..


Thanks for all your ideas. A couple here that I am sure will work in other situations.

Rob
 
Rob, could you fill us in on how you coded that, and what version of vs.net you're using? They may have added it to visual studio.net 2003, but for those of us using vs.net 2002 there is no read only attribute for the checkbox control

D'Arcy
 
D'Arcy,

sorry... I replied without testing.. The ASP only folks suggested it, and like a great bonehead I just accepted that it would work.. MY BAD!

I guess that leaves me with the DHTML option, or Greyed out Dissabled box's..


Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top