how to show search results on asp.net page

  • Thread starter Thread starter Dica
  • Start date Start date
D

Dica

i apologize for what is no doubt a very rudimentary question, but i'm still
trying to wrap my brain around .net coding habits. in classic asp, if i
wanted to show search results, i'd just post the form data over to another
page or call a showSearchResults sub on the search page. in .net, i can't
post to another page, so i need to show the search results on the same page
as the search form page. i could write a sub in my code behind that would
response.write all the html and dataset info, but i've never been a fan of
doing that (i loose things like colour coded html, have to constantly escape
my quotes, etc). i believe the correct solution should be to simple take the
html i want to use to display the search results and embed that in a sub on
the .aspx page, and then call the sub from my code behind, but i get a
compile error when i try to run it:



Statement cannot appear within a method body. End of method assumed



is this the way i should be doing things? i don't really want to get into
the habit of response.redirect with all the form values appended to query
string, since this means i have to code another results page, and i'd prefer
to keep the number of pages down to a bare minimum for maintenance's sake.



why am i getting an error with trying to embed the search results sub on the
search form page?



tks
 
Dica,

There is nothing wrong with a response direct when you are showing a
completly new page.

However when you do the method you use now, can that as well preferable, it
goes normally quicker and looks more smooth.

However what goes wrong is impossible to say from the possition we are
looking. We don't see the code that gives your error. So when you show that
too us, it probably can give more results (and not the whole program and
when you want that more persons look to it, than past it first in a
notebook, copy it back and than in the message, otherwise it becomes mostly
unreadable)

Cor
 
Cor Ligthert said:
Dica,

There is nothing wrong with a response direct when you are showing a
completly new page.

However when you do the method you use now, can that as well preferable, it
goes normally quicker and looks more smooth.

not sure i follow you. showing search results on the same page is
preferable?
However what goes wrong is impossible to say from the possition we are
looking. We don't see the code that gives your error. So when you show that
too us, it probably can give more results (and not the whole program and
when you want that more persons look to it, than past it first in a
notebook, copy it back and than in the message, otherwise it becomes mostly
unreadable)

here's a very stripped down version of the page (gives me the same error).
it
throws an error on the sub declaration (sub showSearchResults). i don't
think there's any need to include the codeBehind since it throws the error
on page load:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="indexTmp.aspx.vb"
Inherits="HP.index"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>HP Products Search Page</title>
<script language="vb" runat="server">

</script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="styles/hp_main.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="frm1" method="post" runat="server">

<table>
<tr>
<td><p style="FONT-WEIGHT: bold">Search:</p>
</td>
<td><asp:TextBox id="txtSearchUsingAll" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="You must enter a search string"
ControlToValidate="txtSearchUsingAll">*</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td><input class="CRLbutton2" id="Reset1"
onclick="javascript:ClearSearchAll(778);" type="reset" value=" Clear » "
name="button1"></td>
<td><input class="CRLbutton2" id="Search" type="submit" value=" Search »
" name="cmdSearch" runat="server"></td>
</tr>

</table>


<% sub showSearchResults() %>
<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tr>
<td valign="top" align="center"><img src="images/hpinvent.gif"></td>
<td valign="top"><h1>Search Results</h1></td>
</tr>

</table>
<% end sub %>

</form>
</body>
</HTML>


tks for your help
 
Dica,

You are using in this page very few aspnet however probably a big
JavaScript.

The connection between JavasScript and serverside is not the nicest thing to
do.

In my opinion it would be better when you would first try some expirience
with some easier applications.

Create a new webpage. Set that as startpage, drag a button on a that. Click
on that button, that open the code behind and change the name of the text on
the button.

button1.text = "Dica"

It takes 10 minutes however than you probably see where your problem in this
page is.

I hope this helps,

Cor
 
Cor Ligthert said:
Dica,

You are using in this page very few aspnet however probably a big
JavaScript.

yes, i'm trying to keep things as simple as possible to narrow down the
problem.

upon additional research, it looks like using "<% %>" to segregate my code
from html is frowned upon in .net (though i'm not too sure why. this is just
what i've picked up from misc. comments). the recommened fix is to put the
code inside script tags as follows:

"<script runat="server" language="vb">
sub showSearchResults()

'// do whatever //
end sub
</script>"

but this goes back to the original problem i have with response.write(ing)
all my html in code. i just want to encapsulate html within a sub i can
call. isn't there a simple way to do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top