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. document.getElementById Not work With Masterpage ASP.Net VB

document.getElementById Not work With Masterpage ASP.Net VB

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nethelp
12 Posts 5 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.
  • E El_Programmer

    you must be more explicit with your request. what are you trying to do and what code are you writing, where is the Label, in master page or in the page, from where are you calling it???

    D Offline
    D Offline
    Diyaa Hamza
    wrote on last edited by
    #3

    this is my code <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript" src="js/timer.js"></script> <script type="text/javascript"> window.onload = WindowLoad; function WindowLoad(event) { ActivateCountDown("CountDownPanel1", document.getElementById('lbltime').value, "CountDownEnded1"); } function CountDownEnded1() { alert("Time End"); location.reload(true); } </script> <asp:Label ID="lbltime" runat="server" Visible="false"></asp:Label> I Want to get the text in "lbltime" to my code

    E N K 3 Replies Last reply
    0
    • D Diyaa Hamza

      this is my code <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript" src="js/timer.js"></script> <script type="text/javascript"> window.onload = WindowLoad; function WindowLoad(event) { ActivateCountDown("CountDownPanel1", document.getElementById('lbltime').value, "CountDownEnded1"); } function CountDownEnded1() { alert("Time End"); location.reload(true); } </script> <asp:Label ID="lbltime" runat="server" Visible="false"></asp:Label> I Want to get the text in "lbltime" to my code

      E Offline
      E Offline
      El_Programmer
      wrote on last edited by
      #4

      ok, if you notice, you are asking for the value of the Label(lbltime) but it has not a text property which will be the equivalent of "Value". So what you have to do is something like: or if you are assigning a value (Text) from the server side, you must do it before the form call for the javascritp code, in Page_Prerender event.

      N 1 Reply Last reply
      0
      • E El_Programmer

        ok, if you notice, you are asking for the value of the Label(lbltime) but it has not a text property which will be the equivalent of "Value". So what you have to do is something like: or if you are assigning a value (Text) from the server side, you must do it before the form call for the javascritp code, in Page_Prerender event.

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #5

        El_Programmer wrote:

        if you are assigning a value (Text) from the server side, you must do it before the form call for the javascritp code, in Page_Prerender event.

        What? :confused: You are not even close to what the problem is. JavaScript object do have a Value property.


        I know the language. I've read a book. - _Madmatt

        E 1 Reply Last reply
        0
        • D Diyaa Hamza

          this is my code <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript" src="js/timer.js"></script> <script type="text/javascript"> window.onload = WindowLoad; function WindowLoad(event) { ActivateCountDown("CountDownPanel1", document.getElementById('lbltime').value, "CountDownEnded1"); } function CountDownEnded1() { alert("Time End"); location.reload(true); } </script> <asp:Label ID="lbltime" runat="server" Visible="false"></asp:Label> I Want to get the text in "lbltime" to my code

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #6

          ASP.NET adds some name mangling to control ids when they are rendered. The controls are prefixed with the container name such as: Content1_lbltime. Since you are looking specifically for an element with the id lbltime this obviously won't work. I would strong suggest you use JQuery and something like this

          var value = $("id[$='lbltime']").val();

          This says to get the element with an id that ends with 'lbltime' and retrieve its value. This will find the control no matter what prefix has been added


          I know the language. I've read a book. - _Madmatt

          D 1 Reply Last reply
          0
          • N Not Active

            El_Programmer wrote:

            if you are assigning a value (Text) from the server side, you must do it before the form call for the javascritp code, in Page_Prerender event.

            What? :confused: You are not even close to what the problem is. JavaScript object do have a Value property.


            I know the language. I've read a book. - _Madmatt

            E Offline
            E Offline
            El_Programmer
            wrote on last edited by
            #7

            i mean if you want to assign any text to your label(lbltime) from the server side, in Page_Load or Page_Prerender. because when you call your javascript code your label has no text, that is why you are getting and NULL value. did you get it?

            N 1 Reply Last reply
            0
            • E El_Programmer

              i mean if you want to assign any text to your label(lbltime) from the server side, in Page_Load or Page_Prerender. because when you call your javascript code your label has no text, that is why you are getting and NULL value. did you get it?

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #8

              That is not why the OP is getting a NULL. Read below. Did you get it?


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              • N Not Active

                ASP.NET adds some name mangling to control ids when they are rendered. The controls are prefixed with the container name such as: Content1_lbltime. Since you are looking specifically for an element with the id lbltime this obviously won't work. I would strong suggest you use JQuery and something like this

                var value = $("id[$='lbltime']").val();

                This says to get the element with an id that ends with 'lbltime' and retrieve its value. This will find the control no matter what prefix has been added


                I know the language. I've read a book. - _Madmatt

                D Offline
                D Offline
                Diyaa Hamza
                wrote on last edited by
                #9

                This code it's work okay in the page with out Masterpage so the problem is document.getElementById("lbltime").value not work with masterpage I want code work with masterpage

                N 1 Reply Last reply
                0
                • D Diyaa Hamza

                  This code it's work okay in the page with out Masterpage so the problem is document.getElementById("lbltime").value not work with masterpage I want code work with masterpage

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #10

                  Member 7765904 wrote:

                  the problem is document.getElementById("lbltime").value not work with masterpage

                  That is exactly what I'm saying. Have you tried it? What are you having difficulties with? What don't you understand?


                  I know the language. I've read a book. - _Madmatt

                  1 Reply Last reply
                  0
                  • D Diyaa Hamza

                    Hi I Was try to get value for label by JavaScript but I got Problem with reading the value it's NULL :(

                    G Offline
                    G Offline
                    GenJerDan
                    wrote on last edited by
                    #11

                    Look at the source code of the webpage when it comes up. The ID of the label is not what you think it is...because of the MasterPage.

                    There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

                    1 Reply Last reply
                    0
                    • D Diyaa Hamza

                      this is my code <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript" src="js/timer.js"></script> <script type="text/javascript"> window.onload = WindowLoad; function WindowLoad(event) { ActivateCountDown("CountDownPanel1", document.getElementById('lbltime').value, "CountDownEnded1"); } function CountDownEnded1() { alert("Time End"); location.reload(true); } </script> <asp:Label ID="lbltime" runat="server" Visible="false"></asp:Label> I Want to get the text in "lbltime" to my code

                      K Offline
                      K Offline
                      ktrrzn
                      wrote on last edited by
                      #12

                      Hi, I suggest this solution, it works for me. in your JS add variable, and assign the ClientID of ur label control.

                      <b>var slbltime = '<%=lbltime.ClientID%>'</b>

                      window.onload = WindowLoad;
                      function WindowLoad(event) {

                      ActivateCountDown("CountDownPanel1", document.getElementById(<b>slbltime</b>).value, "CountDownEnded1");

                      }

                      bcoz when .Net render asp control to html control, they need to give id to it. if u use asp:label control, the id will transform into 'Master_ct00_lbltime' something like that. as far as i know, what other member want to say is if u assign value into ur label control from code behind file(.aspx.cs) u need to do b4 PreRender state of page life cycle. PreRender is the state b4 the asp:control are actually transform into html control to send it to the web browser. Hope it works!

                      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