View Full Version : Stopping a search when the page loads

Gary Williams
10-23-2003, 01:06 PM
Hi All,

I have a single asp page that contains a form with a dropdown box to select a variable in one field of an mdb file.

The asp code to perform the search is also on this page, along with the code to display the recordset.

When the page first loads, it always displays the complete database. Once loaded, if I then use the dropdown box, all works perfectly.

How do I stop this initial search? I have tried using an 'onLoad' function to call a javascript, and:

If Request.QueryString("cboStatus")<>"live" then
... do search ...
Response.write("Please make your Selection")
End If

to try to stop the search . Nothing stops it as yet.

Any Idea's?



10-23-2003, 01:42 PM
when you use a multipurpose page, it's best to check at the top of the page, if the page has already been submitted or if this is the initial load. Like
if Len(request.form("search")) > 0 then ' this means there is a value for the formfield named "search"
run your selectcode and display results
display the initial form
end if
--> this supposes you use the post method (<form method="post" ...>) and that your submitbutton has (name="search"). Or you can call the dropdown "search"

You now probably have a where clause that always evaluates true if there is no value selected (or the where clause isn't add to the query if there was no value selected)

Gary Williams
10-23-2003, 03:46 PM
Hi Raf,

That fixed it.

To make the form work, I have to use the 'get' function, so I used 'if Len(Request.QueryString) > 0 then' etc, etc.

I set the initial selected value of the dropdown to empty ("") and now it doesn't trigger a search when the page is loaded.