Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 864
  • Last Modified:

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

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
JOHNFROG
Asked:
JOHNFROG
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
silemoneCommented:
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
 
leakim971PluritechnicianCommented:
You may sync the value with an hidden field
0
 
silemoneCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
silemoneCommented:
The other way I was going to suggest would be a hidden field as leakim stated.
0
 
JOHNFROGAuthor Commented:
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
 
amit_gCommented:
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
 
FredTangCommented:
please try this:

dim strLablevalue as string

strLablevalue=this.Lbl_id.value
0
 
JOHNFROGAuthor Commented:
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
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now