I have a custom web control *.ascx file. I am trying to simulate the user clicking the update button in a gridview using a java script. I have this script at the top of my .ascx page :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript">
$(document).keypress(function (e) {
if (e.which == 13) {
document.getElementById("LinkButton1").click();
}
});
</script>
The “LinkButton1” is located in this template field:
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" onKeyPress="" UseSubmitBehavior="True" CausesValidation="True"
CommandName="Update" TabIndex="13" Text="Update" ></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
What am I missing or doing wrong?
That won’t work because the click only works for attached events not for an anchor which is what a linkbutton is rendered as.
You can use this ..
function simulate(element, eventName) {
var options = extend(defaultOptions, arguments[2] || {});
var oEvent, eventType = null;
}
function extend(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
var eventMatchers = {
‘HTMLEvents’: /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
‘MouseEvents’: /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
};
var defaultOptions = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
bubbles: true,
cancelable: true
};