Help Me Help Me - 6 months ago 32
HTML Question

How to send input text values from html to VB.NET

I am trying to code this but I find it hard to solve it. I'll just show you the image of the scenario.

enter image description here

html code:

<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 code

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

Answer

The ToString method is just going to return the type of the object return by GetElementById and not the value of the input in the HTML. To get the latitude, or whatever, use the GetAttribute method and pass in "value". So your Sub could be coded as:

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