Laurence
Laurence

Reputation: 1020

Using JavaScript to do ASP.NET postback (clicking LinkButton) - postback occurs but not Click event

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

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.

Upvotes: 0

Views: 7348

Answers (1)

Roimer
Roimer

Reputation: 1459

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.

Upvotes: 2

Related Questions