I have a simple aspx page. After loading the page I want a button to be pressed.
Here is the button that I want to click:
<asp:Button class="js-modal js-prevent-bg-click inline" id="invisibleSelectProducer" href="#" runat="server" Text="Select Producer"></asp:Button>
Here is the jquery that I have added that (I would have thought) should click the button once the page is finished loading:
<script language="javascript" type="text/javascript">
$(document).ready(function () {
console.log($("#invisibleSelectProducer"));
$("#invisibleSelectProducer").click();
});
</script>
Am I missing something completely obvious? Even the log that I added (above) logs the button object that I want to click. But the code immediately following does nothing.
EDIT After trying Mike123's suggestion, I have the following code. It still does not work though. Once again, the console will let me see the button object (so I know it is rendered) but the .click() is not firing off once the page loads.
<script language="javascript" type="text/javascript">
$(document).ready(function () {
console.log($("#<%=invisibleSelectProducer.ClientID%>"));
$("#<%=invisibleSelectProducer.ClientID%>").click();
});
</script>