Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i am for my text box i am implimenting the ajax calender so the text in the text box is text or date i want find. if it is text means i want to display popup. is it possible

first i want to know how to give the condition

But now i am using this condition
C#
if ( txtAppDate.Text.ToString() == "")
                {
                    string radalertscript1 = "<script language='javascript'>function f(){alert('Please select the Appointment Date ', 330, 210,'My Title'); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript1);
                    return;
                }
Posted
Updated 17-Jul-13 21:06pm
v3
Comments
Dholakiya Ankit 18-Jul-13 3:08am    
in javascript?

use RegularExpressionValidator and capture the isValid property if it is valid then it is date if Invalid then it is text.
 
Share this answer
 
Comments
ntitish 18-Jul-13 3:25am    
can u give any sample example.....
Zafar A khan 18-Jul-13 3:32am    
check this
http://stackoverflow.com/questions/4284280/date-regular-expression-validator
http://sandblogaspnet.blogspot.com/2009/04/calling-validator-controls-from.html
ntitish 18-Jul-13 3:39am    
sir can i use this sir,

try
{
txtDt.Text = Convert.ToDateTime(txtDt.Text).ToString("dd-MMM-yyyy");
}
catch (Exception eee)
{
txtDt.Text = "";
}
if (txtDt.Text.Trim() == "")
{
ClientScript.RegisterStartupScript(GetType(), ClientID, "alert('Enter Valid Date');", true);
return;
}
Zafar A khan 18-Jul-13 3:48am    
DateTime mydate = null;
if (DateTime.TryParse(txtDt.Text, out mydate))
{
}
else {
ClientScript.RegisterStartupScript(GetType(), ClientID, "alert('Enter Valid Date');", true);
}
ntitish 18-Jul-13 3:56am    
Cant i check in first if statement itself sir........
In both JavaScript or .NET, it's the best to just try to parse string into date/time and see if it fails or not.

—SA
 
Share this answer
 
Comments
ntitish 18-Jul-13 3:26am    
sir can u give any example for my above code......
ntitish 18-Jul-13 3:38am    
Sir can i use this ha sir

try
{
txtDt.Text = Convert.ToDateTime(txtDt.Text).ToString("dd-MMM-yyyy");
}
catch (Exception eee)
{
txtDt.Text = "";
}
if (txtDt.Text.Trim() == "")
{
ClientScript.RegisterStartupScript(GetType(), ClientID, "alert('Enter Valid Date');", true);
return;
}
Sergey Alexandrovich Kryukov 18-Jul-13 10:27am    
Why "Convert"? You need DateTime.Parse... TryParse/ParseExact/TryParseExact.
Don't use "", use string.Empty.
Even if this is work, I suspect you tent to use strings representing data, not data itself (System.DateTime). Don't "convert" string to string. Always work with data. Strings are only needed on the very end of output: to show on screen, etc.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900