One of the most frequent frustration while quickly adding some code snippets in ASP.Net page is the problem of nested <form> tags forbidding . Thus, you cannot write:
<form id=”form1”…>
…
<form id=”form2”…>
…
</form>
…
</form>
Particularly, it is generating problems while adding automatically generated google search box to the master pages of BlogEngine .Net themes. The Google’s code uses the tag <form>. The same tag is used at least for the themes side panel. It means we cannot just put the Google’s code into the side panel. I think it is the reason why I haven’t see the themes having a Google search box. Anyway, a lot of themes having Google ads are present :-)
Here I present a solution by presenting a special web control for BlogEngine .Net. Control is replacing the initial standard code, simulating entirely the look&feel and behaviour of standard Google search box. Additionally, Google ads are generated and treated as well.
Installation
0. Register with Google Analytics and obtain the javascript scripts of your ads and search box. Extract from scripts and write down the parameters google_ad_client, google_ad_slot and cx (necessary on the step 4.)
1. Download the file GoogleSearchBox.cs.
2. Copy the file into the site to the folder /App_Code/Controls.
3. Rebuild the site, if necessary.
4. Open the site.master file in the theme you use and add where you want the code:
<blog:GoogleSearch ID=”google” runat=”server” Google_ad_client = "pub-4872819432540437" Google_ad_slot = "3391639644" Google_search_box_cx = "partner-pub-0464579479626999:lr8yub7qkzy" />
where Google_ad_client, Google_ad_slot and Google_search_box_cx are the values of parameters google_ad_client, google_ad_slot and cx, extracted from the javascript, generated by Google. Like this one:
<script type="text/javascript"><!--
google_ad_client = "pub-4872819432540437";
/* 468x60, 04.12.09 */
google_ad_slot = "3391639644";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Also here are plenty of additional parameters for additional customizing position of Google controls.
Enjoy!