Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help with Form Validation

Status
Not open for further replies.

linuxjr

Programmer
Jun 2, 2001
135
US
Hello Everyone,
I need some assistance with my form validation. I have been given a project by my boss and not given a lot of time to finish it. The project I have been given is to have a form where the user can select a date range and some other filters to be passed to a crystal report popup.

I have the crystal report popup working with the values passed from the form if the user does everything correctly. Anyways I need help with date validation and formatting the date as the user finishes typing the date. I wanted to know if I have to do this in Javascript or are there some C# functionality that will assist me with checking to make sure the end date is not greater than the start date. Also to be able to check after a user types in a date that it is in the correct format?

Any tips or hints will be greatly appreciated. I tried searching this site but at the moment the feature is down so I do apologize if this has been asked a bunch of times.

Have a great day.
 
Mr. Greer,

I thank you for your quick response. I would prefer using Javascript myself. I went to the link you posted and got the isDate function added to my html code in webform1.aspx. I then try to add to the OnTextChanged method to the textbox control in the html portion as follows:

<asp:textbox id="txtStartDate" OnTextChanged="isDate(txtStartDate.Text);" runat="server"></asp:textbox>

I get an error CS1026: ) expected. Am I missing something like do I need to add the TextChanged Event to my code behind in my webform1.aspx.cs file??

Any tips or suggestions be greatly appreciated. Have a nice day.
 
The proper JavaScript event handler for the "change" event is:

Code:
onchange()

The proper way to pass a control's value to a JavaScript function is to use the "this" keyword:

Code:
isDate(this.value)

If you are doing client-side validation, this doesn't really need to be a server control.

Since it is a server control, your Page_Load event needs to add the event handler attribute and function call, like so:

Code:
txtStartDate.Attributes.Add("onchange","isDate(this.value)");

If you found this post helpful, you can support Tek-Tips by visiting some of the ads/sponsors. You can thank me by visiting my site, and clicking some of the ads there.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Mr. Greer,
Thank you so much for taking time out of your busy schedule to answer my questions. It finally works properly. I will visit you site when I get off work and check out some of the ads to assist you. Have a great day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top