Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Making Fields read-only

Making Fields read-only

Scheduled Pinned Locked Moved ASP.NET
jsontutorial
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    macca24
    wrote on last edited by
    #1

    On my web form I have a dropdown list. What I want is when I select "Closed" in the drop down list then the rest of the fields on the web form will be rendered Read-only as the form is not to be edited after it has been "Closed". Anyone any ideas how to do this. macca

    V P T 3 Replies Last reply
    0
    • M macca24

      On my web form I have a dropdown list. What I want is when I select "Closed" in the drop down list then the rest of the fields on the web form will be rendered Read-only as the form is not to be edited after it has been "Closed". Anyone any ideas how to do this. macca

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Hi macca: In the onChange event of dropdown, you need to have a clientside JavaScript which should check the value. If it is closed then, you can get all textBoxes via document.getElementsByTagName("input") and if it is text, then you can set readOnly = true. readOnly may not be supported by other type of controls which support only disabled. Also, check out the compatibility against Netscape/FireFox. Deepak Kumar Vasudevan Personal Web: http://vdeepakkumar.netfirms.com/ I Blog At: http://deepak.blogdrive.com/

      M 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        Hi macca: In the onChange event of dropdown, you need to have a clientside JavaScript which should check the value. If it is closed then, you can get all textBoxes via document.getElementsByTagName("input") and if it is text, then you can set readOnly = true. readOnly may not be supported by other type of controls which support only disabled. Also, check out the compatibility against Netscape/FireFox. Deepak Kumar Vasudevan Personal Web: http://vdeepakkumar.netfirms.com/ I Blog At: http://deepak.blogdrive.com/

        M Offline
        M Offline
        macca24
        wrote on last edited by
        #3

        Thanks for the reply. Could you give me some example code as I am not sure of Javacript. macca

        1 Reply Last reply
        0
        • M macca24

          On my web form I have a dropdown list. What I want is when I select "Closed" in the drop down list then the rest of the fields on the web form will be rendered Read-only as the form is not to be edited after it has been "Closed". Anyone any ideas how to do this. macca

          P Offline
          P Offline
          Plunging_Falcon
          wrote on last edited by
          #4

          In addition to what the gentleman who replied first suggested, you could alternatively use the SelectedIndexChanged event of the dropdown and write server-side code that disables the controls (control.Enabled = false;). Falcon.

          1 Reply Last reply
          0
          • M macca24

            On my web form I have a dropdown list. What I want is when I select "Closed" in the drop down list then the rest of the fields on the web form will be rendered Read-only as the form is not to be edited after it has been "Closed". Anyone any ideas how to do this. macca

            T Offline
            T Offline
            totig
            wrote on last edited by
            #5

            It depends on how your dropdown list is working. If you are causing a postback each time, then set each field to read only on the server side. eg TextBox1.ReadOnly = true; if your dropdown list does not post back, you will have to implement this in javascript.

            M 1 Reply Last reply
            0
            • T totig

              It depends on how your dropdown list is working. If you are causing a postback each time, then set each field to read only on the server side. eg TextBox1.ReadOnly = true; if your dropdown list does not post back, you will have to implement this in javascript.

              M Offline
              M Offline
              macca24
              wrote on last edited by
              #6

              Thanks for the replies guys. Toticow how do you set the dropdown list to Post Back. In the PageLoad I have my page set to: If Not Page.IsPostBack Then page info...... Do I have to change the page.ispostback or can I do it another way? macca

              T 1 Reply Last reply
              0
              • M macca24

                Thanks for the replies guys. Toticow how do you set the dropdown list to Post Back. In the PageLoad I have my page set to: If Not Page.IsPostBack Then page info...... Do I have to change the page.ispostback or can I do it another way? macca

                T Offline
                T Offline
                totig
                wrote on last edited by
                #7

                Ok, firstly ensure the dropdownlist is set to autopostback (In the designer, set this to true). In the PageLoad Event, do something like IF(IsPostBack) { if (DropDownList.value = "nothing")//Basically check for the word you want to search { textBox1.readonly = true; } }

                M 1 Reply Last reply
                0
                • T totig

                  Ok, firstly ensure the dropdownlist is set to autopostback (In the designer, set this to true). In the PageLoad Event, do something like IF(IsPostBack) { if (DropDownList.value = "nothing")//Basically check for the word you want to search { textBox1.readonly = true; } }

                  M Offline
                  M Offline
                  macca24
                  wrote on last edited by
                  #8

                  Thanks for the help. That's workin fine now. macca

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups