I want to call a c# function using javascript, so I added an invisible asp.net button to my Default.aspx, and now I am tring to call it inside javascript so that it will trigger the c# function, but it gives 'null' is null or not an object. I tried to move my javascript part to many places to solve the problem but it didn't work.
<asp:Content ID="HeaderContent" runat="server"
ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2> WELCOME </h2>
<div style="display: none;">
<asp:Button ID="button1" runat="server"
OnClick="btn_SearchLibrary_Click" />
</div>
<script type="text/javascript">
function displaymessage() {
var button = document.getElementById('button1');
button.click();
}
</script>
<!-- Some codes in here, below there is a gridview templatefield -->
<asp:TemplateField HeaderText="BookName"
SortExpression="BookName" ItemStyle-Width="150px">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1"
runat="server" Text='<%# Bind("BookName") %>'
NavigateUrl="javascript:displaymessage()"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>