Sitefinity ASP.NET CMS - Content Management System

Support Forum Thread

Home >  Support >  Forums home > Sitefinity 3.x > Pre-release forums (retired) > Setting the index of search module at runtime

Reply
puneet, 3/17/2008 5:12:02 AM


I made 4 index for search module and i want to set the index at runtime based on the value selected in the dropdown box.

How i can do that.....


Reply
, 3/17/2008 9:40:16 AM
Hi puneet,

Here is a simple example how to achieve this with a User Control wrapping the SearchBox control that is shipped with Sitefinity:

.ascx
<%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls" TagPrefix="sitefinity" %> 
 
<div> 
    <asp:DropDownList ID="IndexCatalogue" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SearchIndexes_SelectedIndexChanged"></asp:DropDownList> 
</div> 
<div> 
    <sitefinity:SearchBox ID="SearchBox1" runat="server" ResultUrl="~/ResultUrlPage.aspx"></sitefinity:SearchBox> 
</div> 

.ascx.cs
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            this.BindIndexCatalogue(); 
        } 
    } 
 
    protected void SearchIndexes_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        this.SearchBox1.IndexCatalogue = ((ListControl)sender).SelectedValue; 
    } 
 
    void BindIndexCatalogue() 
    { 
        this.IndexCatalogue.DataSource = IndexingManager.IndexingServices.Values; 
        this.IndexCatalogue.DataTextField = "Name"
        this.IndexCatalogue.DataValueField = "Name"
        this.IndexCatalogue.DataBind(); 
 
        this.IndexCatalogue.Items.Insert(0, new ListItem("Please, select an index"string.Empty)); 
    } 

After creating the control you need to upload it in the "Add Controls" toolbox. For more information, please, refer to the User Manual -> Working with Controls.

Hope this is helpful for you.

Greetings,
Pepi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center

Reply
puneet, 3/17/2008 12:25:10 PM
i made user control containg the code u specified but when i am building the web site than it is showing the error that "IndexingManager is not defined"
Do i need toinclude any telerik framework in my cs class of the user control?

Other than that r u understanding my problem completely or not .I want to tell u once again the exact problem

Problem is:

In sitefinty serah control there is a textbox in which we will eneter some string right?
i already made four indexes to search

Now i want user to enable to select one of the search index for search module
So i place a dropdown right beneath the textbox of search module to have the user entry..

Based on the user entry i have to select one of the index made by me for searching 

this is my problem
i am
Suppose we place search module on our page and than we are editing 

Reply
puneet, 3/18/2008 4:48:09 AM
I made user control as you specified .but after uploading the user control ,No control gets added in sitefinty control section..
Reply
puneet, 3/18/2008 4:53:33 AM

there is also one more problem in the.ascx page.that if i move to the design tab of the .ascx page than dropdown shown fine but <Sitefinity:SearchBox1 ......
  > does not render but it sends the exception that "Unhandeled exception has occured. Object reference not set to an instance of an object.

I uses the

<sitefinity:SearchBox id=SearchBox1 __designer:dtid="1407383473487872" runat="server" ResultUrl="~/SearchResult.aspx">

Reply
puneet, 3/18/2008 4:53:38 AM

there is also one more problem in the.ascx page.that if i move to the design tab of the .ascx page than dropdown shown fine but <Sitefinity:SearchBox1 ......
  > does not render but it sends the exception that "Unhandeled exception has occured. Object reference not set to an instance of an object.

I uses the exactly same

<sitefinity:SearchBox id=SearchBox1 __designer:dtid="1407383473487872" runat="server" ResultUrl="~/SearchResult.aspx">

Reply
puneet, 3/18/2008 4:53:43 AM

there is also one more problem in the.ascx page.that if i move to the design tab of the .ascx page than dropdown shown fine but <Sitefinity:SearchBox1 ......
  > does not render but it sends the exception that "Unhandeled exception has occured. Object reference not set to an instance of an object.

I uses the exactly same html for my

<sitefinity:SearchBox id=SearchBox1 __designer:dtid="1407383473487872" runat="server" ResultUrl="~/SearchResult.aspx">

Reply
puneet, 3/18/2008 4:53:47 AM

there is also one more problem in the.ascx page.that if i move to the design tab of the .ascx page than dropdown shown fine but <Sitefinity:SearchBox1 ......
  > does not render but it sends the exception that "Unhandeled exception has occured. Object reference not set to an instance of an object.

I uses the exactly same html for my >ascx

<sitefinity:SearchBox id=SearchBox1 __designer:dtid="1407383473487872" runat="server" ResultUrl="~/SearchResult.aspx">

Reply
puneet, 3/18/2008 6:11:16 AM
Now i want to replace the search button of search module of sitefinity with the image?
Reply
, 3/20/2008 11:14:31 AM
SearchBoxTemplate_with_Image.zip
Hi puneet,

Now i want to replace the search button of search module of sitefinity with the image?

Reading this question, I assume that you have solved your other problems with the custom control that we have provided earlier.

You can change the search button with an image very easily. You just need to edit the template of SearchBox, because as Pepi said earlier, the custom control inherits the functionality of the SearchBox control.
The template is located in <your project>\Sitefinity\ControlTemplates\Search. I am attaching a new template with ImageButton instead a regular button. Take a look at this, it should change the button with a clickable Telerik logo.

Regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center

Reply
Zubair, 4/2/2008 4:42:48 AM
Hi,

My issue is with the default paging mechanism in Search Results,

I want to show the pager

< Goto Page 1               [Page 1 of 1]         Goto Page 2 >

Please tell me how to do this.

Thanks

Reply
, 4/7/2008 6:42:34 AM
Hello Zubair,

The template you should edit is SearchResult.ascx located in \[YourProject]\Sitefinity\ControlTemplates\Search.

Following your questions, I think it's worth mentioning that all templates that are applied to the public controls are in the ControlTemplates directory.

Kind regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center

Reply
Zubair, 4/7/2008 6:45:51 AM
Sorry for not being clear, I do know which control I need to edit, but what I don't know is how to read total page number as well as previous and next page numbers to make my pager look like above.
Reply
, 4/11/2008 5:18:44 AM
Hi Zubair,

Here's how you can read the current page number and the total page number :
// Total Pages 
<asp:Literal ID="PageNumberLiteral"  
     runat="server"  
     Text='<%# pager1.PageCount.ToString() %>' /> 
// Currently selected page 
<asp:Literal ID="LiteralCurrentPage" 
     runat="server"  
     Text='<%# pager1.SelectedPage.ToString() %>' /> 

SelectedPage is from type "int", so if you would like to take the next page or the previous page, just add or substract one :
<asp:LinkButton ID="next" runat="server"
           text
='<%#(pager1.SelectedPage+1).ToString() %>'/> 

I hope you find this answer helpful.

Greetings,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center

Reply
Zubair, 4/12/2008 11:39:56 PM
yes, looks like this is what I wanted. I'll try it and give you the feedback.

Thanks.

Reply
Zubair, 4/13/2008 2:39:42 AM
Can you please tell me how to wire the <Goto Page 1 and Goto Page 2> buttons to their respective events just as Previous/Next buttons.

Thanks.

Reply
Zubair, 4/13/2008 2:55:32 AM
Nevermind, I set the controls ID to the old IDs and it works. Thanks :)