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. Display message on asp label by using Javascript.

Display message on asp label by using Javascript.

Scheduled Pinned Locked Moved ASP.NET
javascripthelptutorial
3 Posts 3 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
    AndieDu
    wrote on last edited by
    #1

    Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.

    S B 2 Replies Last reply
    0
    • A AndieDu

      Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.

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

      AndieDu wrote:

      Add OnClientClick="UpdateLabelMessage()" to button control. Then in Javascript, you need to do something like:

      function UpdateLabelMessage()
      {
      document.getElementById('lblMessage').text = "Message updated";
      }

      P.S.: label id used in Javascript might change based on the design of your webpage, you can check viewsource to get exact id to use in JS.

      1 Reply Last reply
      0
      • A AndieDu

        Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.

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

        As you made your Label visible false, it wont render on the page and can not be made visible fron javascript. So better make it like

        <asp:label ID="Label1" runat="server" text="Label" style="display:none;"></asp:label>

        Now you would be able to show from javascript. Add onClientClick as Sandeep suggested like OnClientClick="ShowLabel();" and your js function would be

        function ShowLabel()
        {
        document.getElementById("<%=Label1.ClientID %>").style.display='';
        document.getElementById("<%=Label1.ClientID %>").innerHTML="Updated Text";
        }

        Let me know for any query

        Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0

        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