If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Checking the date before passing on to stored procedure

Hello All. I have a form that sumbits data into a database, along with the current date and time as a stamp. However, I would like to create something that checks the date before any data is inserted into my table. I only want to allow the data to be entered if the current date is between the first and the 25th of the month. In other words, If today's date is between the 26th and the 31st (or the last day of the month) I want an error message to appear that says "You cannot insert this data right now. Please try again next month." How would i go about doing this?

To get the error into an annoying little alert box you would have to use asp.net to write out java script. response.write("java script here"). But I prefer to keep it all server side, I would just write the text on the screen and not write out the form or make the form invisible server side.

Originally posted by roteague You are better off using a RangeValidator control. It is all client side. I can elaborate if you need it.

if its all client side then it will fail for 13% of the internet. The best thing would be to make this server side, then go back and write java script for use conveiniance and a little extra bandwidth you can save. But if you put your trust in anything completely client side, expect it to fail for a certain percent for your users and cause flaws in your application.

RangeValidators are still the way to go. By default they are client-side if the browser supports them, otherwise they do their validation on the server. If you want to do all validation on the server, you can still use RangeValidators. See the June 2004 issue of Visual Studio Magazine, an article titled "Validate Complex Client Data" for example on how to use these on the server.

I would still prefer to do it in raw code because when using a validator, of any type, it is still going to output bad code. It will output javascript without the type attribute etc. I like control over my output. Until the output has been cleaned up in another version I refuse to use things like built in pageing, validators, or the calander control. I actualyl would prefer to use html forms too. The control that I find mose conveiniant is the repeater, because I still get complete markup control and it saves a lot of code from looping through data like in asp classic. But I refuse to loose control over the markup. I want my sites to be valid and accessible.

Re: Checking the date before passing on to stored procedure

Performance tip:

Instead of calling 3 stored procedures in the code you show, create a new stored procedure to handle all three actions and call it instead. Even if the new stored procedure just EXECs the other 3 stored procedures, it'll still be much more efficient.