Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2003, 05:52 AM
Registered User
 
Join Date: Jul 2003
Location: gorey, , Ireland.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default pass javascript value to label

I need to pass value from a javascript function to a label in an asp/aspx page.
I cannot find information on this anywhere,
has this been done before

can anybody help
Reply With Quote
  #2 (permalink)  
Old July 17th, 2003, 06:10 AM
Authorized User
 
Join Date: Jul 2003
Location: Houten, Utrecht, Netherlands.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bosboom
Default

The only way to do this is to load a .asp page in a browser, so i suggest to use a <iframe> or hidden frame in your page and load the page which updates the value with javascript like so:

hiddenframe.location.href="yourpage.asp?value=your value"

GreetZ

Bosboom

Reply With Quote
  #3 (permalink)  
Old July 17th, 2003, 07:52 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you mean change an asp:label control from client-side JavaScript without posting then you need to know the clien-side id of the control. A label control is only an HTML span element. I believe you can set this server-side using clientID property.
Then in your client-side JavaScript
Code:
  function setLabelText(ID, Text)
  {
    document.getElementById(ID).innerHTML = Text;
  }
Then call this function from somewhere, assuming id is "ctrl1"::
Code:
  setLabelText("ctrl1", "Hello, World.");
--

Joe
Reply With Quote
  #4 (permalink)  
Old August 30th, 2006, 02:29 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that was helpful...

it works!!!

Reply With Quote
  #5 (permalink)  
Old July 3rd, 2008, 12:55 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how do i access the innerText or the innerHTML property of a label using the C# code behind ? please let me know

Reply With Quote
  #6 (permalink)  
Old July 3rd, 2008, 03:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Don't reply to very old posts with an essentially unrelated question.

And in any case, you should have posted this in the C# forum.

But whatever...

The simple answer: YOU DON'T.

C# code *ON THE SERVER* can *ONLY* see information that is passed to it FROM A FORM on the client. So you would have to use JavaScript in the HTML page to copy the innerHTML value to a form field (presumably, a HIDDEN form field) so that the server could the read it.

Incidentally, innerText is not supported in all browsers. You probably should stick with innerHTML.
Reply With Quote
  #7 (permalink)  
Old July 4th, 2008, 03:06 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm new to this forum. I'm a bit annoyed to see this kinda rude reply !! Thanks for the reply anyways ... and this was an essentially related question.

Reply With Quote
  #8 (permalink)  
Old July 5th, 2008, 04:04 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Even if you saw your question as related to the old thread, you would get a much better reponse (most of the time) if you posted in the right forum.

JavaScript truly is just for client-side use. And it really has nothing (directly) to do with C# programming or with server-side code, in general.

If you don't yet understand the difference between client and server, that's okay. But now is the time to learn the difference, before you go off on a long journey down the wrong path. I remember a person who wrote an incredibly long and complex set of ASP (pre-ASP.NET) pages that freely mixed JavaScript in the browser and server-side coding. And he managed to make it all work on his own personal machine. But when he went to deploy it to the 'net, of course it fell flat on its face. Because he didn't understand that ONLY on his local machine were the browser and the server the same machine, with the same resources. He had to throw away weeks and weeks of work and start all over.

So if I seem over-emphatic, sorry. But I'm really just trying to save you time and effort. Save you hours if you are lucky, days if you are not.

Anyway, from my viewpoint your question is utterly unrelated to the old thread. How you get information from server to browser is, indeed, completely different from how you get information from browser to server. The server can easily put anything to the browser any way it wants to. Dirt simple. The browser can *ONLY* influence the server by sending data back to the server by means of a query string or post data. (With ASP.NET--and excepting for Ajax--99% of the time post data is used, but that's mainly because of the standard controls in the MS "toolkit".)

So... If I irritated you, it wasn't on purpose. But if I irritated you into thinking about how client/server really works, then it was worthwhile, anyway.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass javascript variable to xsl eruditionist XSLT 4 September 8th, 2008 08:37 AM
Change ASP.NET label color using Javascript shalan99 ASP.NET 2.0 Professional 4 May 22nd, 2007 02:09 AM
How To Pass Javascript variable to vbscript pbcatan Classic ASP Databases 1 December 18th, 2006 08:42 AM
How Do I Pass 2 Variables in Javascript Lucy Javascript 2 December 13th, 2003 11:25 AM



All times are GMT -4. The time now is 08:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.