ASP. Correct way to check a form has been sent.

I have decided to write a template ASP file as most of the ones I write do the same thing (run a query and show a table) with slight variations between each one.

I usually check one field to see if it’s time to start processing the input…

if request.querystring(“field”) = “” then

But I am pretty sure this isn’t the most correct way of doing it. So what is?

As this is a template I want to be correct :slight_smile:

Another question. I want to give me the option of including a file or not. Since an ASP include is already using html comments is there a way of doing it without adding asp wrappers (<% and %> and then adding a quote?) that seems ott and only confuses the code… I’m tring to simplify the code.
In other words I want a way to disable a line like this…

<!–#include file=“includes\aninclude.asp”–>

without resorting to this…


'<!–#include file=“includes\aninclude.asp”–>


And one more question. How do I reset the page from a link on the page so the fields are blanked again, without having to use the name of the page?

Re: question 2:

You can’t do an include that way. Includes are processed BEFORE any code is executed. If you want to do a conditional include, you need to use the EXECUTE method.

The reset button?

In your form use a hidden tag

<input type="hidden" name="IsPostBack" value="1">

Then, on the code that handles the submission:

If Request.Form("IsPostBack") = 1 Then 
 .... do form stuff
End If

If you want a button to reset a form, use a reset button

<input type="reset" id="btnReset" value="Clear Form">

If you want to get a page’s name w/o knowing it:


And then look into using ASP.NET instead because ASP classic is on it’s way out in a big way.

It works.

What you might not be realizing is that I’m creating a template. The idea being that I’ll create a new file with it and manually, with my fingers, make the include ‘work’ again.

So the thing that decides the condition is not code, it’s me. (in the future when I come to use this template)

But your link might work anyway :slight_smile:

I think I’ll convert to PHP when I decide to ditch ASP.

Thanks for the answers BTW :slight_smile:

In that case, couldn’t you just include it like this?

<!--include file="includes\aninclude.asp"-->

Without the ‘#’ it would be treated as a standard HTML comment. To actually include it, add the ‘#’

<!--#include file="includes\aninclude.asp"-->

Is there a variant of request.servervariables(“script_name”) that gets the url without any passed data (nothing after the .asp)

It’s for a ‘back to data entry’ link. I don’t want to use the ‘reset’ way because that means extra code in places.

If that works then perfect! I’ll use that in my template, and in the comments above I’ll put…

'If you need to use this include add the ‘#’ key before ‘include’

Thanks again all. I am looking for this template to require the minimum of thinking for it to be turned into something useable.

Not to my knowledge (not that it’s impossible … I’m no encyclopedia …). I would just split the string at “.asp”, take Array(0), and re-concatenate it with a new “.asp” on the end.

Who will be viewing this template? If you might publish the page without activating the include, I’d recommend commenting it out with the leading apostrophe, instead. The way you do it above, anyone can see the name of your included file by choosing “view source” in their browser. The other way, it’s invisible. Just something to consider.

Is it right for comments to be included as page source? Wouldn’t it be more sensible for the browser to leave them out?

Anyway, the template is likely only ever to be seen by me, but anyone who uses my creations (a medium size team of people) can, if they wanted to, view source and see what’s in those includes anyway… That is to say they’ll see the compiled HTML, not the ASP :smiley:

p.s. I’ll give your string manipulation idea a try.
I think what I was asking might be possible in PHP but that isn’t much more than a guess.