Upon clicking the Log In button, I am faced with two issues. Firstly, when prompted by localhost to allow access, the pop-up disappears in a split second after one click. Only upon double-clicking does it persist at the bottom of the screen, allowing the Ajax method to run. My goal is to have this window consistently appear with just one click.
Secondly, my challenge lies in accessing txtUserName within the Ajax method. Any guidance on how to accomplish this would be greatly appreciated.
Code Behind :
[System.Web.Services.WebMethod]
public static string SendLocation(object Latitude, object Longitude)
{
Core dal_ = new Core();
Model.Team obj_ = new Model.Team();
//obj_.UserName = ?????
obj_.Latitude = Convert.ToDecimal(Latitude);
obj_.Longitude = Convert.ToDecimal(Longitude);
dal_.UpdateTeamCoordinat(obj_);
return "";
}
JavaScript (in asp.x) :
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="js/yqlgeo.js"></script>
<script type="text/javascript">
function initiate_geolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
}
else {
yqlgeo.get('visitor', normalize_yql_response);
}
}
function handle_errors(error) {
switch (error.code) {
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timedout");
break;
default: alert("unknown error");
break;
}
}
function normalize_yql_response(response) {
if (response.error) {
var error = { code: 0 };
handle_error(error);
return;
}
var position = {
coords:
{
latitude: response.place.centroid.latitude,
longitude: response.place.centroid.longitude
},
address:
{
city: response.place.locality2.content,
region: response.place.admin1.content,
country: response.place.country.content
}
};
handle_geolocation_query(position);
}
function handle_geolocation_query(position) {
PageMethods.SendLocation(position.coords.latitude, position.coords.longitude);
}
</script>
Asp.x:
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="LoginButton" runat="server" Text="Log In" OnClientClick="initiate_geolocation()"
OnClick="LoginButton_Click" />