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. Changing LabelText via Java Script

Changing LabelText via Java Script

Scheduled Pinned Locked Moved ASP.NET
csharpjavajavascriptasp-netsysadmin
9 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.
  • V Offline
    V Offline
    vivekphlp
    wrote on last edited by
    #1

    I have a label in my aspx page & iam changing its text via document.getElementById("LabelID").­ innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.

    Proud To Be an Indian

    N A 3 Replies Last reply
    0
    • V vivekphlp

      I have a label in my aspx page & iam changing its text via document.getElementById("LabelID").­ innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.

      Proud To Be an Indian

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      I have not tried this. Just a wild guess. Try changing to ­innerText.

      document.getElementById("LabelID").­innerText = "SOmeText";

      Navaneeth How to use google | Ask smart questions

      modified on Monday, September 28, 2009 10:15 AM

      M 1 Reply Last reply
      0
      • N N a v a n e e t h

        I have not tried this. Just a wild guess. Try changing to ­innerText.

        document.getElementById("LabelID").­innerText = "SOmeText";

        Navaneeth How to use google | Ask smart questions

        modified on Monday, September 28, 2009 10:15 AM

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

        Navaneeth, I think the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.

        N 1 Reply Last reply
        0
        • V vivekphlp

          I have a label in my aspx page & iam changing its text via document.getElementById("LabelID").­ innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.

          Proud To Be an Indian

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          AFAIK, there is no way to get the value on server which is changed by JS for a label. Label is rendered as HTML span and the values of HTML elements like this are not posted to server. If you know CSS, you can make a text box look like a label and change the text box value. Please ignore my previous reply.

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          • M majee

            Navaneeth, I think the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            majee wrote:

            the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.

            For server controls, the id will be put as name. So what you are saying won't occur. The real issue here is a label render as HTML span and contents of span will not be posted to server. See my latest reply. :)

            Navaneeth How to use google | Ask smart questions

            M 1 Reply Last reply
            0
            • N N a v a n e e t h

              majee wrote:

              the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.

              For server controls, the id will be put as name. So what you are saying won't occur. The real issue here is a label render as HTML span and contents of span will not be posted to server. See my latest reply. :)

              Navaneeth How to use google | Ask smart questions

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

              N a v a n e e t h wrote:

              For server controls, the id will be put as name. So what you are saying won't occur. The real issue here is a label render as HTML span and contents of span will not be posted to server. See my latest reply.

              True :)

              1 Reply Last reply
              0
              • V vivekphlp

                I have a label in my aspx page & iam changing its text via document.getElementById("LabelID").­ innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.

                Proud To Be an Indian

                A Offline
                A Offline
                Abhishek Sur
                wrote on last edited by
                #7

                Use <asp:hiddenControl to change its value. Anything other than input types are reflects its changes through javacript in server (Not even Serverside ReadOnly/Disabled TextBoxes). So even if you change the innerHTML of the control, you will not find it in server side. Rather use

                document.getElementById("hiddeninput").value = "SOmeText"; // To find the value in server
                document.getElementById("LabelID").innerHTML = "SomeText"; // For display purpose only.

                I hope this will help you. :rose::rose:

                Abhishek Sur


                My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                **Don't forget to click "Good Answer" if you like to.

                V 1 Reply Last reply
                0
                • A Abhishek Sur

                  Use <asp:hiddenControl to change its value. Anything other than input types are reflects its changes through javacript in server (Not even Serverside ReadOnly/Disabled TextBoxes). So even if you change the innerHTML of the control, you will not find it in server side. Rather use

                  document.getElementById("hiddeninput").value = "SOmeText"; // To find the value in server
                  document.getElementById("LabelID").innerHTML = "SomeText"; // For display purpose only.

                  I hope this will help you. :rose::rose:

                  Abhishek Sur


                  My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                  **Don't forget to click "Good Answer" if you like to.

                  V Offline
                  V Offline
                  vivekphlp
                  wrote on last edited by
                  #8

                  Thanks Friends .. thanks a lot for you support I implemented a textbox but since that textbox need not be Editable Can i change its style to that of a LABEL

                  Proud To Be an Indian

                  A 1 Reply Last reply
                  0
                  • V vivekphlp

                    Thanks Friends .. thanks a lot for you support I implemented a textbox but since that textbox need not be Editable Can i change its style to that of a LABEL

                    Proud To Be an Indian

                    A Offline
                    A Offline
                    Abhishek Sur
                    wrote on last edited by
                    #9

                    Of course budd. Just add a Textbox. In the server side add:

                    txtbox.Attributes.Add("readonly", "readonly");

                    This will make the textbox readonly and also reflect any data being changed in the client. If you make

                    txtbox.Readonly = true / txtbox.Enabled = false;

                    the textbox value changed in the client will not reflect in the server. Hope you understand. :rose:

                    Abhishek Sur


                    My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                    **Don't forget to click "Good Answer" if you like to.

                    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