T
tshad
I am trying to set some labels to display calculated values with posting
back to the server. So I am using Javascript to set the values of my
asp:label. The problem is that an asp:lavel renders into a span element.
For example:
function SalaryDisplay(me)
{
var salaryMinLabel = document.getElementById("SalaryMin");
salaryMinLabel.value = 200;
alert("after setting salaryMinLabel = " + salaryMinLabel.value);
}
The asp.net object:
<asp:label id="SalaryMin" runat="server" />
Which renders into:
<span id="SalaryMin"></span>
The function seems to find the span fine. The alert box shows that it is
set to 200. But the web page never shows it.
There seemed to be a problem with the span element.
Then I found out that the 'value' property on span does not display. The
newly-created span element
is empty and needs to have a text node appended. So to create the node I do
the following:
var salaryMinLabel = document.getElementById("SalaryMin");
var sMLText = document.createTextNode("200")
salaryMinLabel.appendChild(sMLText);
alert("after setting salaryMinLabel = " +
salaryMinLabel.firstChild.nodeValue);
Even though it displays on the page the viewsource displays:
Yearly Compens:<span id="SalaryMin"></span> /
<span id="SalaryMax"></span>
The value is not there.
This obviously is not going to work. I spent a lot of time getting this
work correctly and just found that if you go back a page (or forward) and
then go back to the page - all this SPAN information that was just generated
is now gone. Probably related to why it doesn't appear in Viewsource even
though it is displaying on the original page.
Is there a way to make sure it stays with the page on repost?
Thanks,
Tom
back to the server. So I am using Javascript to set the values of my
asp:label. The problem is that an asp:lavel renders into a span element.
For example:
function SalaryDisplay(me)
{
var salaryMinLabel = document.getElementById("SalaryMin");
salaryMinLabel.value = 200;
alert("after setting salaryMinLabel = " + salaryMinLabel.value);
}
The asp.net object:
<asp:label id="SalaryMin" runat="server" />
Which renders into:
<span id="SalaryMin"></span>
The function seems to find the span fine. The alert box shows that it is
set to 200. But the web page never shows it.
There seemed to be a problem with the span element.
Then I found out that the 'value' property on span does not display. The
newly-created span element
is empty and needs to have a text node appended. So to create the node I do
the following:
var salaryMinLabel = document.getElementById("SalaryMin");
var sMLText = document.createTextNode("200")
salaryMinLabel.appendChild(sMLText);
alert("after setting salaryMinLabel = " +
salaryMinLabel.firstChild.nodeValue);
Even though it displays on the page the viewsource displays:
Yearly Compens:<span id="SalaryMin"></span> /
<span id="SalaryMax"></span>
The value is not there.
This obviously is not going to work. I spent a lot of time getting this
work correctly and just found that if you go back a page (or forward) and
then go back to the page - all this SPAN information that was just generated
is now gone. Probably related to why it doesn't appear in Viewsource even
though it is displaying on the original page.
Is there a way to make sure it stays with the page on repost?
Thanks,
Tom