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. TextBox Readonly Property

TextBox Readonly Property

Scheduled Pinned Locked Moved ASP.NET
comsysadmin
12 Posts 6 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.
  • A Offline
    A Offline
    Anurag Gandhi
    wrote on last edited by
    #1

    When i am setting the Readonly property of a textbox to true and then, changing the textbox's value, The changed value doesn't get populated to the server on postback. Is there any alternative for this. I achieved this by setting the txtName.Attributes.Add("readonly", "readonly"); Need your comment if there is any better method.

    Anurag Gandhi.
    http://www.gandhisoft.com
    Life is a computer program and every one is the programmer of his own life.

    J B S T 4 Replies Last reply
    0
    • A Anurag Gandhi

      When i am setting the Readonly property of a textbox to true and then, changing the textbox's value, The changed value doesn't get populated to the server on postback. Is there any alternative for this. I achieved this by setting the txtName.Attributes.Add("readonly", "readonly"); Need your comment if there is any better method.

      Anurag Gandhi.
      http://www.gandhisoft.com
      Life is a computer program and every one is the programmer of his own life.

      J Offline
      J Offline
      JHizzle
      wrote on last edited by
      #2

      I'm not sure what you're trying to achieve here? Scenario 1: You want to be able to alter the text so that it gets posted back to the server but in which case...why are you trying to make it read only? Read only means just that, you're not meant to change it. Scenario 2: You want the text to be unchangeable. Use the .enabled flag to false on the control.

      1 Reply Last reply
      0
      • A Anurag Gandhi

        When i am setting the Readonly property of a textbox to true and then, changing the textbox's value, The changed value doesn't get populated to the server on postback. Is there any alternative for this. I achieved this by setting the txtName.Attributes.Add("readonly", "readonly"); Need your comment if there is any better method.

        Anurag Gandhi.
        http://www.gandhisoft.com
        Life is a computer program and every one is the programmer of his own life.

        B Offline
        B Offline
        Brij
        wrote on last edited by
        #3

        It is not allowed to change the value of the textbox which is readonly. When it is readonly then why are you changing it. What is your requirement?

        Cheers!! Brij Check my latest Article :A walkthrough to Application State

        A 1 Reply Last reply
        0
        • B Brij

          It is not allowed to change the value of the textbox which is readonly. When it is readonly then why are you changing it. What is your requirement?

          Cheers!! Brij Check my latest Article :A walkthrough to Application State

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          The textbox is readonly for the user. But i want to change it through javascript based on some criteria and get the changed value to the server.

          Anurag Gandhi.
          http://www.gandhisoft.com
          Life is a computer program and every one is the programmer of his own life.

          B 1 Reply Last reply
          0
          • A Anurag Gandhi

            When i am setting the Readonly property of a textbox to true and then, changing the textbox's value, The changed value doesn't get populated to the server on postback. Is there any alternative for this. I achieved this by setting the txtName.Attributes.Add("readonly", "readonly"); Need your comment if there is any better method.

            Anurag Gandhi.
            http://www.gandhisoft.com
            Life is a computer program and every one is the programmer of his own life.

            S Offline
            S Offline
            Sandeep Mewara
            wrote on last edited by
            #5

            Anurag Gandhi wrote:

            the Readonly property of a textbox to true and then, changing the textbox's value,

            How are you able to change a value of textbox when it's readonly? Readonly means you cannot change. & If you want to change why readonly?

            A 1 Reply Last reply
            0
            • S Sandeep Mewara

              Anurag Gandhi wrote:

              the Readonly property of a textbox to true and then, changing the textbox's value,

              How are you able to change a value of textbox when it's readonly? Readonly means you cannot change. & If you want to change why readonly?

              A Offline
              A Offline
              Anurag Gandhi
              wrote on last edited by
              #6

              Sorry for my initial post. I am changing the textbox value in the the client side using Javascript.

              Anurag Gandhi.
              http://www.gandhisoft.com
              Life is a computer program and every one is the programmer of his own life.

              S 1 Reply Last reply
              0
              • A Anurag Gandhi

                Sorry for my initial post. I am changing the textbox value in the the client side using Javascript.

                Anurag Gandhi.
                http://www.gandhisoft.com
                Life is a computer program and every one is the programmer of his own life.

                S Offline
                S Offline
                Sandeep Mewara
                wrote on last edited by
                #7

                You have marked the field as readonly. You wont be able to change it and thus you don't find the change on server side. If you want to use a changed value of the shown readonly field, use hidden field for it. Set the new value in hidden field and access it in code-behind.

                P 1 Reply Last reply
                0
                • A Anurag Gandhi

                  The textbox is readonly for the user. But i want to change it through javascript based on some criteria and get the changed value to the server.

                  Anurag Gandhi.
                  http://www.gandhisoft.com
                  Life is a computer program and every one is the programmer of his own life.

                  B Offline
                  B Offline
                  Brij
                  wrote on last edited by
                  #8

                  One more way, you can do this use a property ContentEditable make it false, then you'll be able to update it from client side.But you'll get some warning for this property.Otherwise better way do as Sandeep suggested.

                  Cheers!! Brij Check my latest Article :A walkthrough to Application State

                  A 1 Reply Last reply
                  0
                  • S Sandeep Mewara

                    You have marked the field as readonly. You wont be able to change it and thus you don't find the change on server side. If you want to use a changed value of the shown readonly field, use hidden field for it. Set the new value in hidden field and access it in code-behind.

                    P Offline
                    P Offline
                    Phillip Donegan
                    wrote on last edited by
                    #9

                    Can you not just disable the textbox and then change the text property? Then it will appear as if readonly but you should still be able to change the value.

                    S 1 Reply Last reply
                    0
                    • P Phillip Donegan

                      Can you not just disable the textbox and then change the text property? Then it will appear as if readonly but you should still be able to change the value.

                      S Offline
                      S Offline
                      Sandeep Mewara
                      wrote on last edited by
                      #10

                      Yes we can, it's just that disabled text would be light grayed... and evident that its disabled. If it's not a concerning issue then surely we can go for it. It's just that, one prefers readonly because of the text visibility in general.

                      1 Reply Last reply
                      0
                      • A Anurag Gandhi

                        When i am setting the Readonly property of a textbox to true and then, changing the textbox's value, The changed value doesn't get populated to the server on postback. Is there any alternative for this. I achieved this by setting the txtName.Attributes.Add("readonly", "readonly"); Need your comment if there is any better method.

                        Anurag Gandhi.
                        http://www.gandhisoft.com
                        Life is a computer program and every one is the programmer of his own life.

                        T Offline
                        T Offline
                        T M Gray
                        wrote on last edited by
                        #11

                        Have your javascript set a hidden field and read the value server-side from that.

                        1 Reply Last reply
                        0
                        • B Brij

                          One more way, you can do this use a property ContentEditable make it false, then you'll be able to update it from client side.But you'll get some warning for this property.Otherwise better way do as Sandeep suggested.

                          Cheers!! Brij Check my latest Article :A walkthrough to Application State

                          A Offline
                          A Offline
                          Anurag Gandhi
                          wrote on last edited by
                          #12

                          Brij wrote:

                          you can do this use a property ContentEditable

                          Do we have such Property for TextBox in Asp.Net 4.0??

                          Anurag Gandhi.
                          http://www.gandhisoft.com
                          Life is a computer program and every one is the programmer of his own life.

                          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