Trying to use an image for the search submit button

Topics: ASP.NET 2.0
Feb 23, 2011 at 11:04 AM
Edited Feb 23, 2011 at 11:05 AM

HI all,

I'm trying to use a search image for my blog at http://blog.evonet.com.au/, rather than the default "submit" button.  I am using version 2.0.

In my site.master I have: 

<blog:SearchBox ID="SearchBox1" runat="server" />

I tried going into App_Code/Controls/SearchBox.cs and changed line 64 

From: 

"<input type=\"button\" value=\"{0}\" id=\"searchbutton\" onclick=\"BlogEngine.search('{1}');\" onkeypress=\"BlogEngine.search('{1}');\" />",

To:

"<input type=\"image\" src=\"~/pics/search-form-submit.png\" id=\"searchbutton\" onclick=\"BlogEngine.search('{1}');\" onkeypress=\"BlogEngine.search('{1}');\" />",                

When I do this, the image shows up ok and search works EXCEPT if there are no results to display.  If I type in a search term that I know will fail I get the following error:

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Source File: [PATH]\App_Code\Controls\PostPager.cs    Line: 195 

 

Line 193:            var currentPage = PageIndex();
Line 194:
Line 195:            var visiblePosts = this.Posts.FindAll(p => p.IsVisible);
Line 196:            var postCnt = visiblePosts.Count;
Line 197:

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   App_Code.Controls.PostPager.PagerTag() in [PATH]\App_Code\Controls\PostPager.cs:195
   App_Code.Controls.PostPager.Render(HtmlTextWriter writer) in {PATH]\App_Code\Controls\PostPager.cs:43
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8681289
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
   ASP.themes_evonet_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\xxx\AppData\Local\Temp\Temporary ASP.NET Files\root\4bb290b2\3d36a91f\App_Web_dt8vz4ig.0.cs:0
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) in E:\Projects\BlogEngine-HG-10\Source\BlogEngine\BlogEngine.Core\Web\Controls\BlogBasePage.cs:467
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Any ideas?

Regards,

Bartek

Coordinator
Feb 24, 2011 at 10:05 AM

This seems like this is a problem/bug with the PostPager control trying to access "this.Posts" when it is null (at least it looks like that is what is going on).

In the meantime, I *think* you can fix this by adding "return" in front of BlogEngine.search().  Like this (changes are shown in bold).

"<input type=\"image\" src=\"~/pics/search-form-submit.png\" id=\"searchbutton\" onclick=\"return BlogEngine.search('{1}');\" onkeypress=\"return BlogEngine.search('{1}');\" />",

Feb 24, 2011 at 12:53 PM

Thanks, that did the trick. :-)