3

Is it posible to get a value from a javascript variable and use it into visual basic code without incrusting value on any control.

1
  • It kinda depends on what kind of situation you want to get a javascript variable. Do you want to get it after a button clicked ? Commented Dec 27, 2011 at 2:02

2 Answers 2

9

You cannot access a js-variable from codebehind without any help of a server-control. You could redirect the page to itself and pass that value as URL-Parameter(window.location.href = window.location.href + "?value=test";). But i assume that this is not what you want because it forces a postback. So the best way is to use a hiddenfield:

In javascript function:

<script type="text/javascript">
    function Foo(){
        var hidden=document.getElementById('hidValue');
        hidden.value="test";
    }
</script>

On aspx:

<Input id="hidValue" type="hidden" runat="server" />

In code behind

Protected hidValue As HtmlControls.HtmlInputHidden

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim hiddenValue = hidValue.Value
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

if possible (is available) try to assign value in java to document.cookie = javavalue and then get it from codebehind var x= document.cookie (either via webbrowser or page)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.