Reputation: 1
I have a C# ASP.NET application with some JavaScript components. In particular, there is a JavaScript popup where the user can enter some details and then press ok (JavaScript button) to submit the data. This will then call a JavaScript function Ok() which will process the data and close the popup.
I want the Ok() function to also call click() on an ASP button on the server side, but the event won't fire even though the correct element is captured at runtime.
The code extract in question:
function Ok() {
var btn = document.getElementById("aspBtn");
btn.click();
[ some extra processing ]
}
What baffles me the most is that this exact click() event on this exact button is called in another part of the code successfully. Please advise.
EDIT: I couldn't fix this in a satisfactory manner so instead will use a server button. Not ideal from a UI point of view, but it will have to do.
Upvotes: 0
Views: 2536
Reputation: 471
the asp button id changes when it runs on the browser try this
document.getElementById('<%=aspBtn.ClientID %>').click();
Upvotes: 2
Reputation: 11721
function Ok() {
document.FormName.btn.click();
[ some extra processing ]
}
Upvotes: 0
Reputation: 5211
Use trigger event.
function Ok() {
document.getElementById('<%# aspbutn.ClientId%>').trigger("click");
[ some extra processing ]
}
For further information, see the below link.
http://api.jquery.com/trigger/
Upvotes: 0