CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.classifieds_starter_kit Tags:
Item Type: NewsGroup Date Entered: 2/1/2008 11:59:10 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 29 Views: 43 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
30 Items, 2 Pages 1 2 |< << Go >> >|
roymartian
Asp.Net User
How to stop default display of adverts on homepage2/1/2008 11:59:10 AM

0/0

Guys,

Tried a few things but still cannot stop my test ads showing on default page, really only want ads to show after a search has been completed.

Had good advice from ashmetry re' page_load but still cannot crack the code, could anyone advise? below is my page_load code for search.aspx.vb for www.jobfunk.com

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

_advancedSearchInEffect = Convert.ToBoolean(ViewState("advancedSearchInEffect"))

If Not Page.IsPostBack AndAlso Page.PreviousPage Is Nothing Then

' check if the URL contains a query for ads by a given member

Dim memberQs As String = Request.QueryString("member")

If Not (memberQs Is Nothing) Then

_showCategoryBrowseForTopLevel = True

' pass it on to the hidden AdvSearch control (its stores most search parameters)

AdvancedSearch.SetMemberName(memberQs)

_advancedSearchInEffect = True

ViewState("advancedSearchInEffect") = True

End If

' check if the URL contains a query for ads in a given category

Dim categoryQs As String = Request.QueryString("c")

Dim categoryIdQs As Integer = DefaultValues.CategoryIdMinValue

If Not (categoryQs Is Nothing) Then

If Int32.TryParse(categoryQs, categoryIdQs) Then

_showCategoryBrowseForTopLevel = True

End If

End If

' if no category was specified in the QueryString, we set it the "All Categories" id (0)

SetCurrentCategory(categoryIdQs)

If (_advancedSearchInEffect) Then

SetSearchMessage(2)

Else

SetSearchMessage(1)

End If

End If

If (Page.IsPostBack) Then

If (_advancedSearchInEffect) Then

SetSearchMessage(2)

Else

SetSearchMessage(1)

End If

UpdateUI()

End If

If Not (Page.PreviousPage Is Nothing) Then

' we check if the request was cross-posted by AdvancedSearch.aspx (in which case we expect to find a control "AdvancedSearch")

Dim advParameters As AdvancedSearch_ascx = CType(Util.FindControlRecursively("AdvancedSearch", Page.PreviousPage.Controls), AdvancedSearch_ascx)

If (Not (advParameters Is Nothing) AndAlso advParameters.SearchingByAdvancedCriteria) Then

' we import its properties into the (hidden) AdvancedSearch control on this page

AdvancedSearch.ImportProperties(advParameters)

' copy the values which the AdSearchDataSource needs on this page (SearchTerm comes from SearchTermTextBox, Category comes from the CategoryDropDown control)

SetCurrentCategory(AdvancedSearch.CategoryId)

SearchTermTextBox.Text = AdvancedSearch.SearchTerm

SetSearchMessage(2)

ViewState("advancedSearchInEffect") = True

ElseIf (Not (advParameters Is Nothing) AndAlso Not (advParameters.SearchTerm.Equals(String.Empty))) Then

' carry over just search term as regular search in category

SearchTermTextBox.Text = advParameters.SearchTerm

SetCurrentCategory(AdvancedSearch.CategoryId)

SetSearchMessage(1)

ViewState("advancedSearchInEffect") = False

Else

' a number of pages contain a generic search text box, which posts back to this page.

' if found, import the search term text

Dim CommonSearchTextBox As TextBox = CType(Util.FindControlRecursively("CommonSearchTextBox", Page.PreviousPage.Controls), TextBox)

If Not (CommonSearchTextBox Is Nothing) Then

' query came from Master Page Search Box

SearchTermTextBox.Text = Server.HtmlEncode(CommonSearchTextBox.Text)

End If

' if a category was also specified, import it as well

Dim CommonCategoryDropDown As CategoryDropDown_ascx = CType(Util.FindControlRecursively("CommonCategoryDropDown", Page.PreviousPage.Controls), CategoryDropDown_ascx)

If Not (CommonCategoryDropDown Is Nothing) Then

SetCurrentCategory(CommonCategoryDropDown.CurrentCategoryId)

End If

' if a "What's new within the last x days" was specified, import it

Dim CommonWhatsNewRangeList As DropDownList = CType(Util.FindControlRecursively("CommonWhatsNewRangeList", Page.PreviousPage.Controls), DropDownList)

Dim CommonWhatsNewButton As Button = CType(Util.FindControlRecursively("CommonWhatsNewButton", Page.PreviousPage.Controls), Button)

If (Not (CommonWhatsNewRangeList Is Nothing) AndAlso Not (SearchTermTextBox.Text.Equals(String.Empty))) Then

Dim numDays As Integer = Convert.ToInt32(CommonWhatsNewRangeList.SelectedValue)

AdvancedSearch.DayRange = numDays

SetSearchMessage(2)

Else

SetSearchMessage(1)

End If

End If

End If

End Sub

ashmetry
Asp.Net User
Re: How to stop default display of adverts on homepage2/1/2008 3:46:38 PM

0/0

Try this..

1.In Search.aspx

   Remove DataSourceID="AdSearchDataSource"  from <asp:GridView ID="AdsGrid" runat="server" DataSourceID="AdSearchDataSource" AutoGenerateColumns="False"...

  (So it doesnt Bind the first time the page loads)

2. In the event of the SearchButton_Clicked add something like

AdsGrid.DataSourceID="AdSearchDataSource";

AdsGrid.DataBind();

---OR---

AdsGrid.DataSource = AdSearchDataSource.Select();

AdsGrid.DataBind();

 

See if this works better for you


-Ash
Web:   www.love2trade.com
Blog:   blog.love2trade.com

Please remember to click "Mark as Answer" on this post if it helped you.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/2/2008 7:06:04 AM

0/0

Ash,

Well mate few troubles as half expected.

1. Works well no ads shown on first time page loads, two observations, it also changed my drop down menu default message which was strange to both saying same thing, for locationdropdown and categorydropdown, not sure if this will cause any further issues not sully tested yet seems ok.

2. Tried this,

<asp:Button ID="SearchButton" Runat="server" Text="Search" OnClick="SearchButton_Click" AdsGrid.DataSourceID="AdSearchDataSource"; AdsGrid.DataBind(); />

however 2 errors & 4 warnings,

 Warning 1 Validation (ASP.Net): Attribute 'SelectOptionVisible' is not a valid attribute of element 'LocationDropDown'. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 36 84 C:\...\localstar\
Warning 2 Validation (ASP.Net): Attribute 'OnCategorySelectionChanged' is not a valid attribute of element 'LocationDropDown'. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 37 29 C:\...\localstar\
Warning 3 Validation (ASP.Net): Attribute 'AdsGrid.DataSourceID' is not a valid attribute of element 'Button'. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 39 113 C:\...\localstar\
Error 4 Validation (ASP.Net): This attribute requires a value. If the value is enclosed in quotation marks, the quotation marks must match. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 41 18 C:\...\localstar\
Warning 5 Validation (ASP.Net): Attribute 'AdsGrid.DataBind' is not a valid attribute of element 'Button'. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 41 1 C:\...\localstar\
Error 6 The server tag is not well formed. C:\Users\The Marsden\Desktop\Fatdog\WEB DESIGN\localstar\localstar\Search.aspx 39 

Obviously I am stabbing the dark a bit with this code so would mega appreciate any advice in correct code for searchbutton_clicked, or what I am obviously doing wrong!

As always thanks,

Roy


 

darkknight187
Asp.Net User
Re: How to stop default display of adverts on homepage2/5/2008 11:55:35 PM

0/0

A real quick method to stop it from showing any adds is to make a small change in App_Code/BLL/Ads.vb

remove this line from the getalladdsbyquery section.

If searchTerm Is Nothing Then
    searchTerm = ""
   End If 

With out that line no ads will be displayed.


Be sure to visit www.detelli.com to find and list your Houses for rent

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 5:50:53 AM

0/0

Tried above and it works, however... When try to use my search box and can no longer see any results, is this maybe due to my search box now being in my default page. Could you help with necessary tip to keep adds hidden, but also search to provide results you can see the problem at www.localstar.com.au Almost there!

darkknight187
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 4:39:39 PM

0/0

You have to carry over your search to the results page.

It looks like you just copied the code from search.aspx onto your default page. 

I got it to work by copying how it was done from the advanced search page.

I posted an add for a dvd player, and when you do a search for dvd it pulls up the result.

So it does work.

So you need to decide where you want your search to take place, and where you want the results displayed.

Advanced search is already carrying that search over to search.aspx, so that's one idea.

And the admin search by default does not reveal any search result.

The system is already doing a lot of functions, just copy what's already being done.

 

 

 

 


Be sure to visit www.detelli.com to find and list your Houses for rent

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 7:51:53 PM

0/0

You are correct I did just copy over code from search.aspx page, and I can successfully see your Sony DVD advert.

Just to confirm with you before I start messing too much, I am going to change code from copying over search.aspx to a copy of advanced search code and then should be able to see ads from search on default page.

 Could you also just explain the page and code that is responsible for pulling the adverts displayed, to increase my understanding ?

Will try today, thanks - again.

Roymartian

 

 

darkknight187
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 8:29:42 PM

0/0

roymartian:
then should be able to see ads from search on default page.
 

I thought you DID NOT want to display search results on your default????????

I thought you wanted to enter the search parameters on the default page and view the results on your search.aspx page.

Is this not right???????


Be sure to visit www.detelli.com to find and list your Houses for rent

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 9:15:37 PM

0/0

Apologies for confusion,

I defintely do not want to show ads as default (only after search criteria selected and search button clicked), just wanted to check my understanding was correct, ie,

 I should change copied code of search.aspx for advancedsearch.aspx in default page.

Thanks,

Roy.

roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 9:27:05 PM

0/0

Just to further explain, want to understand exactly what I need to do with regards to;

"You have to carry over your search to the results page" so I can get results shown from setting search criteria and clicking search button.

Promise to stop bugging you after this!

Roy.

ashmetry
Asp.Net User
Re: How to stop default display of adverts on homepage2/6/2008 9:38:34 PM

0/0

To "carry over" from Search page to Results page, you simple set the postback page in Search.aspx to "results.aspx"

Inside Results.aspx, you would do something like

if(Page.PreviousPage != null){

//Suck out all the information that was entered in the previous page and use it on this page 

}


-Ash
Web:   www.love2trade.com
Blog:   blog.love2trade.com

Please remember to click "Mark as Answer" on this post if it helped you.
darkknight187
Asp.Net User
Re: How to stop default display of adverts on homepage2/7/2008 1:13:54 AM

0/0

Everything might have already been set, and you just need to change the button postback url, but if not this will work. 

On the default page remove the object datasource and gridview, and set the button postback url to "Search.aspx or whatever page you want to show results on."

On the code behind (search.asx.vb) you will see this.

' carry over just search term as regular search in category

AdvancedSearch.ImportProperties(advParameters)

Add this:

SearchTermTextBox.Text = advParameters.SearchTerm

Make sure that the search box from the default page where the search is starting has the same Id ie .. SearchTermTextBox

If I remember right it this is already underneath that in the Else section:

Dim CommonSearchTextBox As TextBox = CType(Util.FindControlRecursively("CommonSearchTextBox", Page.PreviousPage.Controls), TextBox)

If Not (CommonSearchTextBox Is Nothing) Then

' query came from Master Page Search Box

SearchTermTextBox.Text = Server.HtmlEncode(CommonSearchTextBox.Text)

End If

And it should carry over the search term, and I think everything was already set to carry over the category aswell.

Just make sure both pages use the same Id on the carry over textbox, and dropdownlist.

 

 


Be sure to visit www.detelli.com to find and list your Houses for rent

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/7/2008 2:16:00 AM

0/0

Big thanks, think I got it, will experiment later today. Will close this thread, hopefully won't need follow up, thanks Ash & Dark Knight!

roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/7/2008 11:08:53 AM

0/0

Tried making default postback to search.aspx however did not work and also could not see your dvd advert.

Then checked to see if search.asx.vb includes your recommended modifications, and the code is already exactly as you recommend to change to ?

Also tried making postback to showAd.aspx no good and also advancedSearch.aspx also no good.

Seems I don't know the correct postback URL location of my adverts !

Could you advise on how I could check, I am hoping all code already set, seems exactly the same, just postback location wrong.

Before any changes postback was not set for search button in default, so I think this is it, but cannot find correct location ?!?

Any recommnedations ?

Roymartian.

darkknight187
Asp.Net User
Re: How to stop default display of adverts on homepage2/7/2008 2:42:41 PM

0/0

Let's see some code from your default page search section, and i'll fix it.


Be sure to visit www.detelli.com to find and list your Houses for rent

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
roymartian
Asp.Net User
Re: How to stop default display of adverts on homepage2/7/2008 5:51:31 PM

0/0

Thanks for this, below is default code...(also put in default.aspx.vb just incase its needed)

Default.

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="Search.aspx.vb"

Inherits="Search_aspx" Title="Melbourne Business Listing Search & Advertising - www.localstar.com.au" %>

<%@ Register TagPrefix="uc1" TagName="AdvancedSearch" Src="Controls/AdvancedSearch.ascx" %>

<%@ Register TagPrefix="uc1" TagName="CategoryDropDown" Src="Controls/CategoryDropDown.ascx" %>

<%@ Register TagPrefix="uc1" TagName="LocationDropDown" Src="Controls/LocationDropDown.ascx" %>

<%@ Register TagPrefix="uc1" TagName="CategoryPath" Src="Controls/CategoryPath.ascx" %>

<%@ Register TagPrefix="uc1" TagName="CategoryBrowse" Src="Controls/CategoryBrowse.ascx" %>

<%@ Register TagPrefix="uc1" TagName="FeaturedAd" Src="Controls/FeaturedAd.ascx" %>

<%@ Import Namespace="AspNet.StarterKits.Classifieds.Web" %>

<asp:Content ID="SecondBarContent" ContentPlaceHolderID="SecondBar" Runat="server">

<script language="javascript" type="text/javascript">

<!--

function FIELDSET1_onclick() {

}

// -->

</script>

<div id="crumbs_text">

<uc1:CategoryPath ID="CategoryPath" Runat="server" OnCategorySelectionChanged="CategoryPath_CategorySelectionChanged" /></div>

</asp:Content>

<asp:Content ID="MainContent" ContentPlaceHolderID="Main" Runat="server">

<div id="body">

<div id="search_n_browse">

<div id="search">

<asp:Panel ID="SearchPanel" Runat="server" DefaultButton="SearchButton">

<fieldset id="FIELDSET1" language="javascript" onclick="return FIELDSET1_onclick()">

<legend>Find my localstar</legend>

<asp:TextBox ID="SearchTermTextBox" Runat="server" CssClass="search_box" />

<uc1:CategoryDropDown ID="CategoryDropDown" Runat="server" SelectOptionVisible="false"

OnCategorySelectionChanged="CategoryDropDown_CategorySelectionChanged" AllCategoriesOptionText="Choose a service or trade" />

 

<uc1:LocationDropDown ID="LocationDropDown" Runat="server" SelectOptionVisible="false"

OnCategorySelectionChanged="LocationDropDown_CategorySelectionChanged" />

<asp:Button ID="SearchButton" Runat="server" Text="Search" OnClick="SearchButton_Click" PostBackUrl="~/Search.aspx" />

<asp:HyperLink ID="AdvancedSearchLink" Runat="server" NavigateUrl="~/AdvancedSearch.aspx">[go to advanced search]</asp:HyperLink>

</fieldset>

<br />

</asp:Panel>

</div>

<div id="browse">

<fieldset>

<legend>Continue Browsing Subcategories</legend>

<asp:ListBox ID="SubcategoriesList" Runat="server" Rows="6" DataSourceID="CategoryDataSource"

DataTextField="NameWithActiveCount" DataValueField="IdString" AutoPostBack="True"

OnDataBound="SubcategoriesList_DataBound" OnSelectedIndexChanged="SubcategoriesList_SelectedIndexChanged">

</asp:ListBox>

</fieldset>

</div>

<br />

<br />

<br />

<br />

<br />

<br />

<br />

</div>

<div id="content_header">

<a id="content_start"></a>

<asp:PlaceHolder ID="SearchingByAdvancedPanel" Runat="server" Visible="false">

<h2>Advanced Search Criteria</h2> <br /><br />

<asp:Label ID="AdvancedSearchCriteria" runat="server"></asp:Label>

<br />

<asp:LinkButton ID="RemoveAdvancedSearch" runat="server"

Text="[remove advanced criteria]" OnClick="RemoveAdvancedSearch_Click"></asp:LinkButton>

</asp:PlaceHolder>

<asp:PlaceHolder ID="NormalSearch" Runat="server" Visible="false">

<asp:Label ID="NormalSearchLabel" runat="server" CssClass="normal_weight"></asp:Label>

<br />

<asp:Label ID="NormalSearchCriteria" runat="server"></asp:Label> <br />

<asp:LinkButton ID="ClearSearch" runat="server"

Text="[clear search]" OnClick="ClearSearch_Click"></asp:LinkButton>

</asp:PlaceHolder>

</div>

<div id="content">

<br />

<asp:Panel ID="ResultsPanel" Runat="server">

<asp:GridView ID="AdsGrid" Runat="server" DataSourceID="AdSearchDataSource" AutoGenerateColumns="False"

DataKeyNames="Id" AllowPaging="True" PageSize="5" AllowSorting="True" CssClass="item_list">

<EmptyDataTemplate>

No Ads were found matching your search.

</EmptyDataTemplate>

<Columns>

<asp:ImageField DataImageUrlFormatString="~/PhotoDisplay.ashx?photoid={0}&amp;size=small"

DataImageUrlField="PreviewImageId" SortExpression="PreviewImageId" AlternateText="Ad preview photo.">

<ItemStyle CssClass="col_photo" />

<HeaderStyle CssClass="col_photo" />

</asp:ImageField>

<asp:HyperLinkField HeaderText="Name" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/ShowAd.aspx?id={0}"

DataTextField="Title" SortExpression="Title">

<ItemStyle CssClass="col_title" />

<HeaderStyle CssClass="col_title" />

</asp:HyperLinkField>

<asp:BoundField HeaderText="Address" DataField="Location" SortExpression="Location">

<ItemStyle CssClass="col_location" />

<HeaderStyle CssClass="col_location" />

</asp:BoundField>

<asp:BoundField HeaderText="Phone Number" DataField="Price" SortExpression="Price" DataFormatString="{0:f}" HtmlEncode="False">

<ItemStyle CssClass="col_price" />

<