如何将输入文本值从html发送到VB.NET

时间:2016-06-03 12:17:53

标签: html vb.net winforms webbrowser-control

我正在尝试对此进行编码,但我发现很难解决它。我只是向您展示场景的图像。

enter image description here

html代码:

<tr>
    <td>Lat</td>
    <td><input type="text" size="20" id="dd_lat" value="38.898556" runat="server"></td>
</tr>
<tr>
    <td>Long</td>
    <td><input type="text" size="20" id="dd_long" value="-77.037852" runat="server"></td>
</tr>

VB.NET代码

Private Sub Button1_ApplyCoordinates_Click(sender As Object, e As EventArgs) Handles Button1_ApplyCoordinates.Click
   Mapping.TextBox2_Latitude.Text = WebBrowser1.Document.GetElementById("dd_lat").ToString
   Mapping.TextBox1_Longhitude.Text = WebBrowser1.Document.GetElementById("dd_long").ToString
End Sub

1 个答案:

答案 0 :(得分:1)

ToString方法只是返回GetElementById返回的对象类型,而不是HTML中输入的值。要获得纬度或其他任何内容,请使用GetAttribute方法并传入&#34; value&#34;。因此,您的Sub可以编码为:

Private Sub Button1_ApplyCoordinates_Click(sender As Object, e As EventArgs) Handles Button1_ApplyCoordinates.Click
   Mapping.TextBox2_Latitude.Text = WebBrowser1.Document.GetElementById("dd_lat").GetAttribute("value")
   Mapping.TextBox1_Longhitude.Text = WebBrowser1.Document.GetElementById("dd_long").GetAttribute("value")
End Sub