First code in which i hardcore the value:
<script type="text/javascript">
function myfunction() {
var label3LatLng =
document.getElementById('<%=TextBox1.ClientID%>').value;
var label4LatLng =
document.getElementById('<%=TextBox2.ClientID%>').value;
L.Routing.control({
waypoints: [
L.latLng(21.5278654, 55.9196996),
L.latLng(23.5278654, 55.9196996)
],
routeWhileDragging: true,
geocoder: L.Control.Geocoder.nominatim()
}).addTo(map);
}
Output:[![Output with hardcore][1]][1]
Code with textbox or labels: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" onclick="myfunction()" value="Click Me"
style="width:300px;">
</td>
</tr>
</table>
<div id="d1"></div>
<script type="text/javascript">
function myfunction() {
var label3LatLng =
document.getElementById('<%=TextBox1.ClientID%>').value;
var label4LatLng =
document.getElementById('<%=TextBox2.ClientID%>').value;
L.Routing.control({
waypoints: [
L.latLng(label3LatLng.trim()), // This assumes the label contains both latitude & longitude.
L.latLng(label4LatLng.trim()) // Note: call trim to remove any potential whitespace.
],
routeWhileDragging: true,
geocoder: L.Control.Geocoder.nominatim()
}).addTo(map);
}
[![Output when entered with TextBox][2]][2]
Even if i enter the values in the Textbox Alert message shows the value but routing machine shows empty values. [1]: https://i.stack.imgur.com/x85v2.png [2]: https://i.stack.imgur.com/7MzyC.png