Solved

ASP.NET Validating for Valid Time Input

Posted on 2012-04-12
3
654 Views
Last Modified: 2013-11-19
I have a textbox where by a time of day is entered. I would like to validate that  a valid time (such as 08:00am) has been entered. At the same time, I do not want to require any input at all.User can leave the box blank if they want.I have an Ajax Extender to help the user enter a valid time if they so choose.

 Also, I would like to only warn the user of entering an invalid time when (and only when) the submit button is clicked. It seems the problem with setting EnableClientScript=true is that if the user clicks inside the text box and and then clicks out the client side validator fires right away. I do not want this.

Further complicating this is it seems that currently simply leaving EnableClientScript=false and Enabled=true(server side validator) doesn't seem to be working at all. It just lets the input through.  How do I get this to work in the manner I have just described. Any advice would be greatly appreciated. .aspx markup is below.

Jason

<asp:TextBox ID="tbCompTime" runat="server" ValidationGroup="grpMainDriver"   MaxLength="10" />
                    
<ajx:MaskedEditExtender ID="meecomptime"  runat="server"   AcceptAMPM="true"   TargetControlID="tbCompTime"  Mask="99:99"  MaskType="Time" MessageValidatorTip="true"> </ajx:MaskedEditExtender> 
<ajx:MaskedEditValidator  ID="mevcomptime" EnableClientScript="false" Enabled="true" ValidationGroup="valComplaintGroup"   runat="server"  ControlToValidate="tbCompTime"  ControlExtender="meecomptime"  IsValidEmpty="True"  InvalidValueMessage="Time not valid"  >   </ajx:MaskedEditValidator>

<asp:Button runat="server" CausesValidation="true" ValidationGroup="valComplaintGroup" id="btnSubmitComplaint" OnClick="btnSubmitComplaint_click" Text ="Submit Complaint"/>

Open in new window

0
Comment
Question by:jazzcatone
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 37838277
Your client validation should be able to manage that the time is empty.

So allow on your client function an empty value and fire that function only on form submit.
0
 

Author Comment

by:jazzcatone
ID: 37838659
So would I have to write the javascript for this? Or is there a way to do this strictly through the .aspx markup
0
 
LVL 19

Accepted Solution

by:
Bardobrave earned 500 total points
ID: 37838776
I think you can do it in both ways, however I'm not used to work with .aspx markup and don't know how to do it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
String manipulation 15 49
C# DataGridView_RowsAdded event not firing 1 40
ASP.NET reading ATOM 2 27
Problem to page 4 27
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now