Problem adding Category DropDownList to SimpleSearch Control

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
webmanWil
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Thu Aug 06, 2009 6:26 pm

Problem adding Category DropDownList to SimpleSearch Control

Post by webmanWil » Tue Aug 18, 2009 4:46 pm

I need to be able to pass the selected category in the querystring to the Search page when the Search button from the SimpleSearch control is clicked. Below is the code from the code page and codebehind of my SimpleSeach control:

CodeBehind ( Categories are bound to the DDL in the InitializeCategoryTree event within this control):
protected void SearchButton_Click(object sender, EventArgs e)
{
string safeSearchPhrase = StringHelper.StripHtml(TxbSearchPhrase.Text);
//CPP - Added categoryID so it could be passed to search page
string categoryID = DdlCategories.SelectedValue;
if (!string.IsNullOrEmpty(safeSearchPhrase))
Response.Redirect("~/Search.aspx?k=" + Server.UrlEncode(safeSearchPhrase) + "&c=" + categoryID);
Response.Redirect("~/Search.aspx");
}


Code Page:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SimpleSearch.ascx.cs"
Inherits="ConLib_SimpleSearch" EnableViewState="false" %>
<%--
<conlib>
<summary>Displays a simple search box where search keywords can be entered, for results the customer will be redirected to search page.</summary>
</conlib>
--%>
Look For&nbsp;
<asp:TextBox ID="TxbSearchPhrase" runat="server" CssClass="searchPhrase"></asp:TextBox>
&nbsp;In&nbsp;
<asp:DropDownList ID="DdlCategories" runat="server" EnableViewState="true" CssClass="searchCategoriesList"
AppendDataBoundItems="True" DataTextField="Name"
DataValueField="CategoryId" AutoPostBack="True"
ondatabinding="DdlCategories_DataBinding"
onselectedindexchanged="DdlCategories_SelectedIndexChanged">
<asp:ListItem Text="- Any Category -" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="BtnSearchButton" UseSubmitBehavior="true" runat="server" Text="Search" OnClick="SearchButton_Click"
CssClass="searchButton" SkinID="ignore" CausesValidation="false" />
&nbsp;
<asp:HyperLink ID="HplAdvancedSearch" NavigateUrl="~/AdvancedSearch.aspx" CssClass="advancedSearchLink"
runat="server">Advanced Search</asp:HyperLink>

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Problem adding Category DropDownList to SimpleSearch Control

Post by mazhar » Mon Aug 31, 2009 8:30 pm

For this you will need to put a dropdown by populating categories in it and finally build search page URL with category parameter against button click to redirect user. Here is modified SimpleSearch control files, download and try these files

webmanWil
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Thu Aug 06, 2009 6:26 pm

Re: Problem adding Category DropDownList to SimpleSearch Control

Post by webmanWil » Tue Sep 01, 2009 6:23 pm

I wasn't able to get this working successfully. It actually does the same thing that the code I created does.
A few problems I'm seeing is that the categories will load into the DDL if not PostBack, but when a PostBack
occurs it loses it's state and all values bound to it. I've tried accessing the SelectedValue of the DDL in various
events, but it's never available. Viewstate doesn't seem to be saving / loading for this control. I manually passed the value of a category and search works fine, just need to pass it programmatically from the DDL.

This is becoming a holdup, hope the problem is found. May have to use Javascript to store value in a client-side field and access it in the click event of the Search button????

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: Problem adding Category DropDownList to SimpleSearch Control

Post by Logan Rhodehamel » Sat Sep 19, 2009 12:04 pm

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SimpleSearch.ascx.cs"
Inherits="ConLib_SimpleSearch" EnableViewState="false" %>
EnableViewState="false" disables viewstate for the whole control.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

webmanWil
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Thu Aug 06, 2009 6:26 pm

Re: Problem adding Category DropDownList to SimpleSearch Control

Post by webmanWil » Sat Oct 24, 2009 7:19 pm

This problem has been resolved. Viewstated had to be enabled on the page and the dropdown list control, then I was able to get the dropdown list values on postback.

Post Reply