document.getElementById Not work With Masterpage ASP.Net VB
-
Hi I Was try to get value for label by JavaScript but I got Problem with reading the value it's NULL :(
-
Hi I Was try to get value for label by JavaScript but I got Problem with reading the value it's NULL :(
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???
-
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???
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 -
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 codeok, 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.
-
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.
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
-
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 codeASP.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
-
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
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?
-
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?
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
-
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
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
-
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
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
-
Hi I Was try to get value for label by JavaScript but I got Problem with reading the value it's NULL :(
-
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 codeHi, 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 b4PreRender
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!