Question

I am using some script to cause a postback. Here is the context:

  • User clicks link to perform a function that needs to know their current location
  • Script gets current location from browser (using navigator.geolocation.getCurrentPosition)
  • When it has the location (the above call is asynchronous - you have to wait for the user to consent to share their location) I want the script to post the location back to the server. I do this by simulating a postback from a hidden link button.

Here is the relevant code:

function submitLocation_Inline(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById("ctr11837_Locator_hLat").value = latitude;
document.getElementById("ctr11837_Locator_hLng").value = longitude;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('ctr11837_Locator_btnSubmitLocation', 'inline');
} 

<a href="javascript:__doPostBack('ctr11837$Locator$btnSubmitLocation','')" id="ctr11837_Locator_btnSubmitLocation"></a>

In the code behind I have a handler for the click event on the hidden linkbutton (btnSubmitLocation_Click). However this is never called. The postback does happen fine, but to process it I have to examine the Request["_EVENTTARGET"] and Request["_EVENTARGUMENT"] during Page_Load to verify it is the postback I want.

How would I adapt my code to cause the btnSubmitLocation_Click to be called?

PS - not sure if this is relevant: the hidden linkbutton is inside an UpdatePanel.

Was it helpful?

Solution

I think that the problem is that you are calling __doPostback() sending the ClientId of the control (I suppose you are using an asp.net link button). Just take a look to the href automatically generated by the linkbutton.

Try calling prm.__doPostBack('ctr11837$Locator$btnSubmitLocation', 'inline') instead.

EDIT: And it looks like you dropped a underscore in prm.__doPostBack(), check your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top