Solved

when using javascript to assign text to an <asp:label> how do you then read that value in code behind vb.net

Posted on 2010-08-31
9
830 Views
Last Modified: 2012-05-10
I have spent hours figuring out how to set the text value of a label using javascript but now after that has been achieved I find that the VB code behind still sees the original default value even after it has been rendered on screen.

So is there anyway to send the output of a javascript back to the server? I thought I could do this using a server control but seems I can only change the rendering of that control, the server doesnt know the value changed.

What I am trying to do is retrieve the timezoneoffset value from the client and use that value to determine a selected item in a listbox.

Is this possible?

Any help is appreciated.
0
Comment
Question by:JOHNFROG
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 33568219
are you using UpdatePanel?
If so, use PageRequestManager (which is javascript).  But with the Sys object, you have more interaction with your java and server controls...
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33568243
You may sync the value with an hidden field
0
 
LVL 21

Expert Comment

by:silemone
ID: 33568262
So since the client isn't refreshing, the server isn't seeing the new values...I would actually just surround the label with an Update Panel (if you only use these on that label, it will not slow down your website) and refresh on a server click, which will be asychronous and will cause only partial page refreshing...
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 250 total points
ID: 33568270
The other way I was going to suggest would be a hidden field as leakim stated.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JOHNFROG
ID: 33568279
yes I am using an update panel. I am starting to understand why thats causing a problem.

will look into PageRequestManager and using a hidden field. but will have to wait until tomorrow now. time has beaten me.
0
 
LVL 58

Expert Comment

by:amit_g
ID: 33568293
asp:Label data is not posted back to server. Use hidden text field in addition to the label. On the client side set the value in the hidden field and then access it on the server.

<input runat="server" type="hidden" id="HiddenVar">
0
 
LVL 5

Expert Comment

by:FredTang
ID: 33568434
please try this:

dim strLablevalue as string

strLablevalue=this.Lbl_id.value
0
 

Author Closing Comment

by:JOHNFROG
ID: 33573295
Using the hiddenfield was the way to go. Although as I was using nested masterpages I had to extend the logic a bit.

To rtrieve the hiddenfield I used the following .vb  function
  Function getValueFromhiddenfield(ByVal curitem As String) As String
        Dim inpt As HtmlControls.HtmlInputHidden = TryCast(Me.Master.Master.FindControl(curitem), HtmlControls.HtmlInputHidden)
        Return inpt.Value
    End Function

And that did it for me.

Thanks for all your assistance
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33575865
You're welcome! Thanks for the points!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now