views:

296

answers:

1

I have a search box web part. In that web part I have created an instance of SearchBoxEx like

SearchBoxEx par=new SearchBoxEx par.goImageUrl="" par.DropDownMode= DropDownModes.DisplayScopeDD; Button sear= new Button(); sear.Click += new EventHnadler(sear_Click);

I have added a button to that search Box web part.Now I have to read the scope selected in the SearchBoxEx in the sear_Click event.Can anyone please guide me in the right direction

Any help would be really appreciated.

A: 

You could read the Request.QueryString["s"] parameter, even when it is a post, the SearchBoxEx adds it.

Edit

Based on the comments and new info, are you using 'pure' javascript? This would be a jquery example:

<a href="#" onclick="newSearchResultsPageWithScope(); return false">Search</a>

WARNING: You should change the site masterpage INSIDE your site with SharePoint designer, not the one in the C:\Program Files\etc... folder. You could also navigate to the

http://yourportal/_catalogs/masterpage
library and download a copy of the default.master to change it then upload it back to the library, do all this carefully, you can break your sharepoint very easily.

Insert above the </HEAD> tag in your masterpage:


<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js">&lt;/script>
<script type="text/javascript">

function newSearchResultsPageWithScope()
{
    var scope = $(".ms-sbscopes select").val();
    location.href = "/CustomResultsPage.aspx?s=" + scope;
}

</script>

The jquery portion is pretty straightforward, it gets the <td> with the class="ms-sbscopes", and the <select> element under it, then it sets the 'scope' variable to the selected value of the scopes dropdown.

Also, customizing the masterpage in a sharepoint site is fine, do not worry with that.

F.Aquino
Thank you for the response. But I am not using default SharePoint search button i.e., I have hidden the magnifying icon and included a search button instead. So in this case the url doesnt have the required query string["s"].
Carol
That is probably why you don't have a scope in the first place :) try to pass the querystring or filling a form input hidden with the value
F.Aquino
Thanks again for response. I am trying to replace default SharePoint search with a different search i.e., results come from different serach engine. But inorder to do that I need to add Java Script function to the default master page which is not recommended.Si I thought of inheriting the default SharePoint Search Box web part and use it. I saw the FAST web parts. They didnt support the scopes. But I have to support the scopes. So I would like to know if I can use same Search dropdown and search box and different search button and use query parametrs and redirectto different results page.
Carol
Yes you can! you just to pass these parameters to your different results page, would that be a problem? I'll edit the post to reflect this new approach
F.Aquino
Thank you very much for your quick response. I would give it a try.I have read some where in the blogs that if we change the default sharepoint files like adding some java script functions to the default master page might cause your solution unsupported by Microsoft sometimes.Is it true? That is the reason why I am going for creating a seperate Search Box Web Part and redirecting my query to a different search engine from there.Thanks Again!!
Carol
Can you tell me where should I add this Java Script code
Carol
Post edited to give you more info, I hope you get it working now!
F.Aquino
Thanks Again!! Sorry to bother you again. If I add this to my master page, when we give the web parts(I have search Box, Search results, Paging etc.,) developed to customers , they need to add this Java Script to their master pages. And when they want to customize or upgrade in future will it have any problems?I am concerned about this. Because some customers don't want to change their default SharePoint files.
Carol
Can I create a feature which would automatically add this java script function to the corresponding site master pages when it is activated?Does that sounds good?
Carol
Could you suggest me a best way to display Search results in SharePoint from a different Search Engine.The options that I am considering are-Include Java Script in the master Page.Create a separate web part page with all the required web parts. Here I am creating a different search box and adding a search button to it which would take to a different page.Thanks for your guidance and responses!!
Carol