Readonly Checkbox

Discussion in 'ASP .Net Web Controls' started by John Kievlan, Jul 29, 2003.

  1. John Kievlan

    John Kievlan Guest

    Well, I'm sure you guys know that the ASP.NET Checkbox
    control doesn't have a Readonly property. I'm writing an
    application where I need it to have, that is, I want to
    be able to set the Checked property in code, but if the
    user clicks on it, the checkbox won't change.

    Now, I'll admit I truly don't know how to do this. I can
    easily write a control where I can't set the Checked
    property in code, as follows:

    '--------- Begin Code --------------
    Public Class CB
    Inherits System.Web.UI.WebControls.CheckBox

    Dim _readonly As Boolean

    Overrides Property [Checked]() As Boolean
    Get
    Return MyBase.Checked
    End Get

    Set(ByVal Value As Boolean)
    If Not _readonly Then
    MyBase.Checked = Value
    End If
    End Set
    End Property

    Property [Readonly]() As Boolean
    Get
    Return _readonly
    End Get

    Set(ByVal Value As Boolean)
    _readonly = Value
    End Set
    End Property
    End Class
    '--------- End Code --------------

    With that control, I can't set the Checked property in
    code, but if I view a form with that control in my
    browser and click on the checkbox, it checks or unchecks
    as usual, which is exactly the opposite of the behavior
    I'd like it to have.

    Now I can't figure out how to get that functionality, or
    indeed how to handle the event of the user clicking on
    the control at all without posting the form back to the
    server. I played with overriding the various Render
    methods, but that got me nowhere.

    The basic problem is that I have no clue how the control
    is drawn as checked or unchecked when the user clicks it
    on his/her browser. Apparently there's no postback (as I
    would assume in any case), so there must be some code
    that runs on the client side to handle it. Can I alter
    that code? How do I get to it? Keep in mind that I want
    this to be a server control, not a client control. I
    really don't even need to mess with the Checked property
    of the control -- if I could just prevent it from drawing
    the checked/unchecked state when it's clicked, I will
    have accomplished what I want, since my goal is to have a
    control in which I can display boolean data without the
    user having the ability to alter the visual state of the
    control.

    Anyone have any ideas? Thanks in advance
     
    John Kievlan, Jul 29, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrei

    Readonly checkbox in Datagrid

    andrei, Jul 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    631
    andrei
    Jul 30, 2003
  2. Cyril

    Checkbox ReadOnly

    Cyril, Apr 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,120
  3. Curt_C [MVP]

    Re: Readonly input checkbox

    Curt_C [MVP], Aug 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,255
    Patrice
    Aug 24, 2004
  4. Todd Cary

    Can a checkbox be READONLY?

    Todd Cary, Dec 30, 2004, in forum: HTML
    Replies:
    12
    Views:
    59,615
    enriquewl
    Jan 20, 2011
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    2,139
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page