[英]Passing Variable from JS to VB.net
我有一個變量,它在js函數中獲取一個值。 我需要將其值作為雙精度值放入vb.net變量中。
我已經嘗試將變量放入標簽中,然后從vb.net中的標簽中抓取它,如下面的代碼所示:
Js部分。
document.getElementById("Label1").innerText = nwLat;
然后在vb部分
Dim nwLat As Double
nwLat = Label1.Text
MsgBox(nwLat)
它不適合我任何想法? 出現的錯誤是輸入字符串格式不正確。
干杯!
沒有任何類型的ajax的最簡單方法是使用隱藏字段。
標記:
<asp:HiddenField ID="nwLatHidden" runat="server" Value="" />
JS:
document.getElementById('nwLatHidden').value = '6.00'; // or of course the value from your function.
回發例程中的.NET:
Dim nwLat As Double
nwLat = nwLatHidden.Value
在JavaScript中:
__doPostBack(
'edit',
JSON.stringify({ ID: id, Code: code, AcctNo: acctNo })
);
在VB.NET中:
Protected Sub Page_Load(s As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'...
Else
Dim eventTarget As String = Request.Form!__EVENTTARGET
Dim eventArgument As String = Request.Form!__EVENTARGUMENT
If Not eventArgument Is Nothing AndAlso Not eventTarget Is Nothing AndAlso eventTarget = "edit" Then
Dim jss As New JavaScriptSerializer()
Dim ac As AccountCode = jss.Deserialize(Of AccountCode)(eventArgument)
End If
End If
End Sub
您需要使用ClientID或UniqueID:
document.getElementById("<%=Label1.UniqueID%>").innerText = "Hi";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.