TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sreenish
NA
249
33.1k
how to make 1 as 01 by entering /
Aug 4 2015 5:02 AM
hi,
in my text box have to do date validations.am done with that. Now if i enter 1/ in that textbox it should return 01 in day place same as in month and year should be like if 15 means 2015.
Source Code::
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dat n Txtbox.aspx.cs" Inherits="Validators.Validators_Task.Dat_n_Txtbox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Custom Validator</title>
<script type="text/javascript">
function FormatMe(n) {
return (n < 10) ? '0' + n : n;
alert("Date");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onclick="FormatMe(n)"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Date is in INVALID Format" ControlToValidate="TextBox1" OnServerValidate="CustomValidator1_ServerValidate" ForeColor="Red"></asp:CustomValidator>
</div>
</form>
</body>
</html>
Code Behind::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
namespace Validators.Validators_Task
{
public partial class Dat_n_Txtbox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs e)
{
DateTime d;
e.IsValid = DateTime.TryParseExact(e.Value, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out d);
}
}
}
Reply
Answers (
1
)
asp button click
image upload