Pass javascript variable to Codebehind

前端 未结 2 1600
傲寒
傲寒 2020-12-07 03:56

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

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 04:26

    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:

    
    

    On aspx:

    
    

    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
    

提交回复
热议问题