.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

How To Validate If TextBox Contains A Valid Date?

Posted By :Mannu     Posted Date :January 13, 2011    Points :15   Category :ASP.Net 
<asp:TextBox ID="txtOnlyValidDate" runat="server"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="txtOnlyValidDate" ErrorMessage="CompareValidator"
Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>



You can also find related Interview Question to How To Validate If TextBox Contains A Valid Date?  below: 

How to validate the listbox for the duplicate values from textbox.

  
It can be done like below-

on the button click event of your add button you can check, if the already entered value and the textbox values are same or not. if both are same, don't allow it else write the new value like below-

foreach(listItem item in ListBox.Items)
{
if(Item.Text != txtbox1.Text)
{
lb.Items.Add(txtbox.Text);
}
else
{
//add the new value;
} (More...)

How you will validate that the selected date from date picker is Monday.

  
first save the date in string like below-

DateTime selecteddate = Convert.ToDateTime(Txtfromdate.SelectedDateValue.ToString());

and then check for monday

if (selecteddate.DayOfWeek != DayOfWeek.Monday)
{
lblmsg.Text = "Yo must select the monday date only";
return;
} (More...)

How can I screen input in a textbox?

  
Yes, For this, it's usually best to start by subclassing the TextBox control so that your solution is reusable within your project (or outside your project). Override OnTextChanged, or for more control, OnKeyPress and OnKeyDown. OnKeyPress fires for printable characters; OnKeyDown fires for all key combinations. Both of these offer a Handled property in the event arguments parameter, which you can set to True to cancel the event. (More...)

Should validation (did the user enter a real date) occur server-side or client-side? Why?

  
Validation will be done in both sides i.e., at the server side and client side. Server side validation will be done even though client side validation performed on the code because of proper
security reasons. (More...)

Does ViewState is responsible for maintaining data across the Page Post Back for Postback controls (like textbox, dropdownlist) and non-postbackcontrols(like label)?

  
It is false. For NonPostback controls it is true but for postback controls, ASP.NET retrieves their values one by one from the HTTP request and copies them to the control values while creating the HTTP response. (More...)

How to Find Number of Days for provided date range?

  
Code extract :

TimeSpan DayDifference = Convert.ToDateTime("2009-1-7").Subtract(Convert.ToDateTime("2009-1-1"));


To find the difference of the days, here we have used Subtract method. The Subtract method does not take start date into consideration. Hence, to get the exact number of days for the date range we need to add one more day to the result.

Response.Write("Number of Days : " + DayDifference.Days+1); (More...)

How to validate a Email-address, in Form using JavaScript?

  
We can validate it through the reg expressions. For example we can declare all the reg expressions of the email in a variable as follows.

var reg = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/; We need to compare the actual value with this expression for the validation. (More...)

What are valid signatures for the Main function?

  
public static void Main ();
public static int Main ();
public static void Main ( string[] args );
public static int Main (string[] args ); (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend