473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with ASP.Net object and Javascript

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:

&nbsp;&nbsp;Yearly Compens:<span id="SalaryMin"></span>&nbsp;/&nbsp;
<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
Nov 19 '05 #1
4 1153
First off, anything you change in javascript isn't going to be visible in
View Source. That just shows the page exactly as it came down from the
server.

Try setting the innerText or innerHTML properties of the span. The 'value'
property is good for input controls, i don't think it works for spans.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
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:

&nbsp;&nbsp;Yearly Compens:<span id="SalaryMin"></span>&nbsp;/&nbsp;
<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

Nov 19 '05 #2
Stick with innerHTML as it's in the W3C standard.

innerText is only support by Internet Explorer.

"Marina" wrote:
First off, anything you change in javascript isn't going to be visible in
View Source. That just shows the page exactly as it came down from the
server.

Try setting the innerText or innerHTML properties of the span. The 'value'
property is good for input controls, i don't think it works for spans.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #3
"gerrod" <ge****@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
Stick with innerHTML as it's in the W3C standard.
How do you set this in Javascript and does it carry over to the asp.net
page?

Does that mean I don't need to add a node as I have been doing?

Thanks,

Tom

innerText is only support by Internet Explorer.

"Marina" wrote:
First off, anything you change in javascript isn't going to be visible in
View Source. That just shows the page exactly as it came down from the
server.

Try setting the innerText or innerHTML properties of the span. The
'value'
property is good for input controls, i don't think it works for spans.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
>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
>


Nov 19 '05 #4
> How do you set this in Javascript and does it carry over to the asp.net
page?
Nope, once it gets back to the server the value will be blank again. If you
want to keep the value once you've posted back to the server, you'll need to
put it into some type of input field, for example a HtmlInputHidden (<input
type="hidden" id="blah" name="blah">). If you don't mark the hidden input
field as runat="server", you'll still be able to access the value via
Request.Form["blah"] (in C#, not sure what VB syntax is).

To set the value via Javascript, it should be just:

var salaryMinLabel = document.getElementById("SalaryMin");
salaryMinLabel.innerHTML = '200';

If you want to set it to a hidden input field (i.e. so it's persisted when
you post-back), it should be just

var salaryMinHidden = document.getElementById("SalaryMinHidden");
salaryMinHidden.value = '200';
Does that mean I don't need to add a node as I have been doing?


Yes, you shouldn't need to add a node.

HTH -
/gerrod
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
5
by: Shawn Modersohn | last post by:
For the script: <script language="JavaScript"> function pullPage(){ var arrayLength=document.teamSelectionF.teamSelectionS.length; var pageNav = new Array(arrayLength); var...
55
by: drhowarddrfine | last post by:
I'm working on a web site that could use some control using js but am concerned about what problems I may have with potential users having their js turned off. Has anyone had any serious problems...
10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
2
by: beseecher | last post by:
Hi, In my research in the javascript language I have encountered problems with implementing prototype inheritance while preserving private methods functioning properly. Here is an example: ...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
1
by: kevin.a.sweeney | last post by:
I would like to open an application from a hyperlink on a webpage. 1. the webpage is located on my local machine. 2. the application is located on my local machine. 3. the application will run...
14
by: julie.siebel | last post by:
I've been wrestling with a really complex page. All the data is drawn down via SQL, the page is built via VBScript, and then controlled through javascript. It's a page for a travel company that...
1
RMWChaos
by: RMWChaos | last post by:
I grabbed this "Rock Solid addEvent" code from this site, which is based on Mark Wubben's event-cache code. (These links for reference only.) I am having two problems with it, and the webmaster is...
10
by: jodleren | last post by:
Hi I know, that there are a lot of people having problems with orkut.com, errors like "object expected" and named objects missing. When loading the site can generate some 10 errors, and still...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.