document.getElementById("<%= btnAlelrt.ClientID %>").click();
If you view source on your generated page you will likely find that the button no longer has the ID "btnAlelrt". It might have something like "ctl001_btnAlert", or some other generated uniqueness identifier.
This is why your javascript isn't finding it.
You'll either need to search by tag, and check the IDs to see if they end in btnAlelrt, or you'll have to place a DIV or SPAN around it with an ID that won't be changed (i.e. doesn't have runat="server"). You can then find that element by its ID, and then get the button inside of it.
If you can, you can use the <%=btnAlelrt.ClientID%> syntax to insert the proper ID in your javascript.
(SIDENOTE:was this supposed to be btnAlert?)
I can't find a code sample to post for you at this moment, but I can explain the problem your having.
ASP.NET doesn't use the ID you give an object /element / button when it writes it to the page, instead it give the object a client ID.
If you do Msgbox(btnAlelrt.clientID) in your code then you will see the object name your javascript should use.
It is better to have the .NET code write out these values, in javascript, to the page, as they are not a constant.
Hope this helps.
James
try using ClientIDMode="Static". this will dont change button id at runtime.
<asp:Button ID="SendMessageButton" ClientIDMode="Static" runat="server" Text="Send Message" CssClass="buttonPositive"
CausesValidation="True" OnClientClick="validate();" OnClick="SendMessageButton_Click" />
Then you can use below jquery to access your button. I hope this helps.
var element = document.getElementById('SendMessageButton');
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.