•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,515 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2710 | Replies: 31
![]() |
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Sorry still being thick, i can't have html and body tags within my search2.aspx page as they're within a masterpage which already defines them, which i think also means i can't have a <script> tag as well? Or am i missing something?
You are bloody impressive for three weeks, i personally think i have begun to experience what hell will be like
An endless ASP.NET project for displaying data about Satan's ass. To be fair that's pretty much what i'm doing now. I must say i have never been convinced about the delights of php before, but god do i love it now, it's so sensible!
And you can use a line or two to do something simple, rather than having to use fifty. 

Dave
You are bloody impressive for three weeks, i personally think i have begun to experience what hell will be like
An endless ASP.NET project for displaying data about Satan's ass. To be fair that's pretty much what i'm doing now. I must say i have never been convinced about the delights of php before, but god do i love it now, it's so sensible!
And you can use a line or two to do something simple, rather than having to use fifty. 

Dave
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
I think i might cry! 
I have tried integrating your code into my page, here is my entire search results page:
I get ltlErrorMessage not declared errors? Do i need to declare it in my aspx.vb page? I'm not entirely sure what you mean about making literal visible=false, is literal not another asp data container? All i really want is the keyword in a string that i can reference on the page!!!
God i can't believe how complicated this is turning out to be, again thank you so so much for spending your time helping me out, you are an absolute god send. Thank you.
Dave

I have tried integrating your code into my page, here is my entire search results page:
<%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="false" CodeFile="search3.aspx.vb" Inherits="search3" title="Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="Panel1" runat="server" BorderColor="#00AEEF" BorderStyle="Solid" Height="100%"
ScrollBars="Vertical" Width="97.5%" HorizontalAlign="Left" CssClass="maincontents">
<script language="vb" runat="server">
Sub Page_Load
Dim strKeyword As String = Request.QueryString("keyword")
Dim intPerPage As Integer = Request.QueryString("perpage")
If strKeyword <> "" Or Not strKeyword = Nothing Then
If intPerPage = "" Or intPerPage = Nothing Then
intPerPage = "5" 'for results incase no perpage is specified.
End If
'you do not need the following line if you make the literal visible=false in the page.
ltlErrorMessage.Visible = False
'Now you can put it anyway you wish, into a datalist, repeater,
'or grid. I would recommend a repeater, unless you need unlimited
'functionality, then use datalist for it's control options.
Else
'not necessarily needed, but extra isn't always bad!
rpSearchResults.Visible = False
ltlErrorMessage.Visible = True
ltlErrorMessage.Text = "There were no keywords specified. Please try again."
End If
End Sub
</script>
<asp:Repeater ID="rpSearchResults" runat="server">
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field to show") %></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Content>I get ltlErrorMessage not declared errors? Do i need to declare it in my aspx.vb page? I'm not entirely sure what you mean about making literal visible=false, is literal not another asp data container? All i really want is the keyword in a string that i can reference on the page!!!
God i can't believe how complicated this is turning out to be, again thank you so so much for spending your time helping me out, you are an absolute god send. Thank you.
Dave
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Check this little bit of genius (not thought up by me obviously!):
This takes the value of the textbox and places it as a variable in the url, just as i want. And in only 4 lines. I take back all the rude things i said about ASP and accept that i am just stupid
I think i'm gonna stick to php after this 
Thanks so so much for taking so much of your time to help me out on this one, it really really is appreciated, hopefully this might be helpful to you sometime
Dave
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Response.Redirect("search2.aspx?keyword=" & txtKeywordxx.Text)
End SubThis takes the value of the textbox and places it as a variable in the url, just as i want. And in only 4 lines. I take back all the rude things i said about ASP and accept that i am just stupid
I think i'm gonna stick to php after this 
Thanks so so much for taking so much of your time to help me out on this one, it really really is appreciated, hopefully this might be helpful to you sometime
Dave
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
That works as well. And the reason why ltlErrorMessage isn't declared is because I never added it to the main page. So it was trying to find the Literal control with the id of ltlErrorMessage although there wasn't one on the page. If you wish, use this updated code.
And the reason why I didn't suggest that last bit of code first is because I didn't think you could reference the control directly through masterpages. I thought you had to find the content panel on the master page, then the control inside the content panel. Masterpages don't seem so threatening now that I know that works.. Then again, when I was trying to work with Masterpages, I was on ASP 1.1 which isn't for masterpages! That code works then, yes. Have you implemented it correctly? Everything works?
<%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="false" CodeFile="search3.aspx.vb" Inherits="search3" title="Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="Panel1" runat="server" BorderColor="#00AEEF" BorderStyle="Solid" Height="100%"
ScrollBars="Vertical" Width="97.5%" HorizontalAlign="Left" CssClass="maincontents">
<script language="vb" runat="server">
Sub Page_Load
Dim strKeyword As String = Request.QueryString("keyword")
Dim intPerPage As Integer = Request.QueryString("perpage")
If strKeyword <> "" Or Not strKeyword = Nothing Then
If intPerPage = "" Or intPerPage = Nothing Then
intPerPage = "5" 'for results incase no perpage is specified.
End If
'you do not need the following line if you make the literal visible=false in the page.
ltlErrorMessage.Visible = False
'Now you can put it anyway you wish, into a datalist, repeater,
'or grid. I would recommend a repeater, unless you need unlimited
'functionality, then use datalist for it's control options.
Else
'not necessarily needed, but extra isn't always bad!
rpSearchResults.Visible = False
ltlErrorMessage.Visible = True
ltlErrorMessage.Text = "There were no keywords specified. Please try again."
End If
End Sub
</script>
<asp:Repeater ID="rpSearchResults" runat="server">
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field to show") %></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Literal ID="ltlErrorMessage" runat="server"><div style="color:#FF0000;font-family:Arial;font-size:11px;">Error: Sorry, there were no keywords found in that search. Please try again.</div></asp:Literal>
</asp:Panel>
</asp:Content>•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Sorry, now keep in mind that the code I just posted doesn't post results... you need to do these steps below to show results:
1. declare a connection, a database comand, and a reader
2. open the connection and run the database command.
3. execute the reader via ExecuteReader() style.
4. Bind the reader to the repeater you have on your page.
I use odbc so this example will show you what you need to know, but won't be exact: Here is the code you need to run the repeater exactly, but change out the variables you need to.
Now, when you take out all the comments, it won't be so much code, and will do wonders for tons of responses. If you're not familiar with SQL, I would add a limit on those return results, otherwise you can have thousands if your database is big enough, which means you would have a huge page..
after the very last bit of the SQL statement, add " LIMIT NumberOfRowsReturned". So LIMIT 10 would return 10 rows of results.
1. declare a connection, a database comand, and a reader
2. open the connection and run the database command.
3. execute the reader via ExecuteReader() style.
4. Bind the reader to the repeater you have on your page.
I use odbc so this example will show you what you need to know, but won't be exact: Here is the code you need to run the repeater exactly, but change out the variables you need to.
<%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="false" CodeFile="search3.aspx.vb" Inherits="search3" title="Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="Panel1" runat="server" BorderColor="#00AEEF" BorderStyle="Solid" Height="100%"
ScrollBars="Vertical" Width="97.5%" HorizontalAlign="Left" CssClass="maincontents">
<script language="vb" runat="server">
Sub Page_Load
Dim strKeyword As String = Request.QueryString("keyword")
Dim intPerPage As Integer = Request.QueryString("perpage")
If strKeyword <> "" Or Not strKeyword = Nothing Then
If intPerPage = "" Or intPerPage = Nothing Then
intPerPage = "5" 'for results incase no perpage is specified.
End If
Dim conPubs As OdbcConnection
Dim cmdSelect As OdbcCommand
Dim dtrReader As OdbcDataReader
'For all the Dims above, you can code the lines below in to form less lines of code.
'I don't like doing it as it looks messy and is problematic for me. Otherwise,
'Delete the lines above and the lines below (where applicable) with these lines below this one.
'Dim conPubs As New OdbcConnection( (System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") )
'Dim cmdSelect As New OdbcCommand( "SELECT * FROM Table WHERE fieldtocompare LIKE '" & strKeyword & "'", conPubs ) 'conPubs.Open()
'Dim dtrReader As OdbcDataReader = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)
'
'The line below references a connection set in the web.config
'file in my site. It's better to use this kind of reference than to
'manually put the connection in every time to reference it.
conPubs = New OdbcConnection( System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") ) cmdSelect = New OdbcCommand( "SELECT * FROM Table WHERE fieldtocompare LIKE '" & strKeyword & "'"", conPubs )
conPubs.Open()
dtrReader = cmdSelect.ExecuteReader()
'another way to avoid having to close the conPubs connection at the
'end of this code, substitute the next line for the one above
'dtrReader = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)
rpSearchResults.DataSource = dtrReader
rpSearchResults.DataBind()
dtrReader.Close()
'if you substituted the dtrReader statements above, remove the line below
conPubs.Close()
Else
'not necessarily needed, but extra isn't always bad!
rpSearchResults.Visible = False
ltlErrorMessage.Visible = True
ltlErrorMessage.Text = "There were no keywords specified. Please try again."
End If
'The lines below just check if the connection is currently open,
'and if it is, close it.
If conPubs.State = ConnectionState.Open then
conPubs.Close()
end if
End Sub
</script>
<asp:Repeater ID="rpSearchResults" runat="server">
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field to show") %></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Literal ID="ltlErrorMessage" runat="server"><div style="color:#FF0000;font-family:Arial;font-size:11px;">Error: Sorry, there were no keywords found in that search. Please try again.</div></asp:Literal>
</asp:Panel>
</asp:Content>Now, when you take out all the comments, it won't be so much code, and will do wonders for tons of responses. If you're not familiar with SQL, I would add a limit on those return results, otherwise you can have thousands if your database is big enough, which means you would have a huge page..
after the very last bit of the SQL statement, add " LIMIT NumberOfRowsReturned". So LIMIT 10 would return 10 rows of results.
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Wow, thanks! That code i printed before does indeed appear to do exactly what i need, parsing the variable via the url. I have just made a drop down box as a second input and have got that variable to be passed as well using the same method. It's like i'm using html forms again 
Is there any reason that you know of why your method is better than the one i listed?
Dave

Is there any reason that you know of why your method is better than the one i listed?
Dave
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Nope. your method is better because you don't have to search all the code for a control. I thought with masterpages you had to use the FindControl() method. Since you don't, yours will be fine, if not better.
Oh, and in the above code, change out the "LIKE '" & strKeyword & "'"" with "LIKE '%" & strKeyword & "%'"
The reason for this is that the '%' allows room for errors. So if you have a keyword named "ame", it will pull all words that have "ame" in it that follow with or end with another letter, like "name" and "same". Understand? It's much better for searching!
If you have any other questions, I will answer them tomorrow morning, or if you're lucky, maybe one more time tonight. I haven't tested that code, but there should be no reason why it doesn't work. I hope I helped!
Oh, and in the above code, change out the "LIKE '" & strKeyword & "'"" with "LIKE '%" & strKeyword & "%'"
The reason for this is that the '%' allows room for errors. So if you have a keyword named "ame", it will pull all words that have "ame" in it that follow with or end with another letter, like "name" and "same". Understand? It's much better for searching!
If you have any other questions, I will answer them tomorrow morning, or if you're lucky, maybe one more time tonight. I haven't tested that code, but there should be no reason why it doesn't work. I hope I helped!
Last edited by SheSaidImaPregy : Oct 22nd, 2007 at 2:21 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Parent/Child Windows References (JavaScript / DHTML / AJAX)
- Nasties and Enigmas (Viruses, Spyware and other Nasties)
- PostBackUrl (ASP.NET)
- deaktop background stuck with Blue color!! (Viruses, Spyware and other Nasties)
- Posting to same page and re-running javascript (JavaScript / DHTML / AJAX)
- Cross-Page PostBack with grouped RadioButtons (ASP.NET)
- :: Network Within Network :: (Networking Hardware Configuration)
- ISSUES w/Graphics, Video, etc on my aging PC (Motherboards, CPUs and RAM)
Other Threads in the ASP.NET Forum
- Previous Thread: Need help passing database column value to a string variable.
- Next Thread: Image Verification in Asp.net



Linear Mode