Why am I getting the message "Can't read the 'click' property of a null error
Inside the tag BODY
:
<asp:Panel ID="nmSearch" CssClass="searchBox" runat="server" DefaultButton="HiddenSearchNM">
<input type="text" runat="server" value="" placeholder="Search" id="searchB" class="styledTB searchB floatLeft" />
<a href="JavaScript:void(0);" onclick="SearchNMClick();" title="Search" class="styledBtnSearch searchAnchor floatLeft defaultLinks">
<asp:Image ImageUrl="~/images/searchWhite.png" CssClass="searchImg" runat="server" ToolTip="Search" AlternateText="Search" />
</a>
<asp:ImageButton ID="HiddenSearchNM" runat="server" CssClass="hideContent" ClientIDMode="Static" />
</asp:Panel>
Inside the tag HEAD
:
<script>
function SearchNMClick() {
document.getElementById('HiddenSearchNM').click();
}
</script>
I see the following error in the console:
Uncaught TypeError: Cannot read property 'click' of null
SearchNMClick
onclick
C # code behind which the search page will be removed from Enter
or press:
protected void HiddenSearchNM_Click(object sender, EventArgs e)
{
//MessageBox.Show("SEARCH NM");
strSMain = searchB.Value;
Response.Redirect("results.aspx?searchtext=" + strSMain +"&folderid=0&searchfor=all&orderby=title&orderdirection=ascending");
}
But when I press Enter while in a textbox or on a button, I get the above error.
How to resolve the error.
So weird, when I check the HTML source, I see this (not sure why the id is changing):
<input type="image" name="ctl00$CUSTOM_Area_Top$HiddenSearchNM" id="ctl00_CUSTOM_Area_Top_HiddenSearchNM" class="hideContent" ClientIDMode="Static" src="" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$CUSTOM_Area_Top$HiddenSearchNM", "", true, "", "", false, false))" style="border-width:0px;" />
+3
source to share