title: Why do I get a "Cannot read property 'click' of null error
body: <p>Inside the <code>BODY</code> tag:</p>
  
  <pre><code>&lt;asp:Panel ID="nmSearch" CssClass="searchBox" runat="server" DefaultButton="HiddenSearchNM"&gt;
      &lt;input type="text" runat="server" value="" placeholder="Search" id="searchB" class="styledTB searchB floatLeft" /&gt;
      &lt;a href="JavaScript:void(0);" onclick="SearchNMClick();" title="Search" class="styledBtnSearch searchAnchor floatLeft defaultLinks"&gt;
          &lt;asp:Image ImageUrl="~/images/searchWhite.png" CssClass="searchImg" runat="server" ToolTip="Search" AlternateText="Search" /&gt;
      &lt;/a&gt;
      &lt;asp:ImageButton ID="HiddenSearchNM" runat="server" CssClass="hideContent" ClientIDMode="Static" /&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>Inside the <code>HEAD</code> tag:</p>
  
  <pre><code>&lt;script&gt;
  function SearchNMClick() {
      document.getElementById('HiddenSearchNM').click();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I see the following error in the console:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'click' of null
  SearchNMClick
  onclick
  </code></pre>
  
  <p>C# code behind which will fire off a search page from either <code>Enter</code> or click:</p>
  
  <pre><code>protected void HiddenSearchNM_Click(object sender, EventArgs e)
      {
          //MessageBox.Show("SEARCH NM");
          strSMain = searchB.Value;
          Response.Redirect("results.aspx?searchtext=" + strSMain +"&amp;folderid=0&amp;searchfor=all&amp;orderby=title&amp;orderdirection=ascending");
      }
  </code></pre>
  
  <p>But when I hit enter while in the textbox or the button click, I get the error above.</p>
  
  <p>How do I resolve the error.</p>
  
  <p>So weird, when I check the HTML source I see this (not sure why the ID is being changed):</p>
  
  <pre><code>&lt;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(&amp;quot;ctl00$CUSTOM_Area_Top$HiddenSearchNM&amp;quot;, &amp;quot;&amp;quot;, true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, false, false))" style="border-width:0px;" /&gt;
  </code></pre>