Search This Blog
Thursday, May 20, 2010
How to validate Email Id
<asp:RequiredFieldValidator ID="RFVtxtEmailID1" runat="server" ControlToValidate="txtEmail"
InitialValue="" Enabled="true" Text="*" ForeColor="Red" Font-Bold="true" ErrorMessage="Enter Email Address">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail"
Display="Dynamic" ErrorMessage="Invalid Email Address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*
</asp:RegularExpressionValidator>
Thursday, May 6, 2010
How to set interval in javascript
<html>
<head>
<script type="text/javascript">
function fls()
{
var date1 = new Date();
if(document.getElementById('spa1').style.color == 'red')
{
document.getElementById('spa1').style.color = 'blue';
}
else
{
document.getElementById('spa1').style.color = 'red';
}
document.getElementById('spa1').innerText = date1;
setTimeout('fls()',1000);
}
</script>
</head>
<body onload="javascript:fls();">
<div id='spa1' style='color: red;font-weight:bold;'> New </div>
</body>
</html>
How to get system date /time using javascript
To get the various fields represented by the data contained in the Date( ) object:
getFullYear( ) return the four digit year
getMonth( ) return the month
getDate( ) return the day of the month
getDay( ) return the day of the week
getHours( ) return the hours
getMinutes( ) return the minutes
getSeconds( ) return the seconds
getMilliseconds( ) return the milliseconds
and to set those fields to a particular value:
setFullYear( ) set the four digit year
setMonth( ) set the month
setDate( ) set the day of the month
setDay( ) set the day of the week
setHours( ) set the hours
setMinutes( ) set the minutes
setSeconds( ) set the seconds
setMilliseconds( ) set the milliseconds
The use of these methods is fairly straightforward and is illustrated in the example below. Take special note, however, of the get and set Day and Month. Day is the day of the week expressed as an integer index value whose range, in typical JavaScript index value fashion, begins at zero. Thus, zero is Sunday, one is Monday, etc. with 6 being Saturday. Similarly, Month ranges from zero (January) to 11 (December).
The following two groups are the equivalent of the above, but where the time and date are expressed as Universal Time (ie GMT - see Timezone Offset in the next part of this series):
getUTCFullYear( ) return the Universal Time four digit year
getUTCMonth( ) return the Universal Time month
getUTCDate( ) return the Universal Time day of the month
getUTCDay( ) return the Universal Time day of the week
getUTCHours( ) return the Universal Time hours
getUTCMinutes( ) return the Universal Time minutes
getUTCSeconds( ) return the Universal Time seconds
getUTCMilliseconds( ) return the Universal Time milliseconds
setUTCFullYear( ) set the Universal Time four digit year
setUTCMonth( ) set the Universal Time month
setUTCDate( ) set the Universal Time day of the month
setUTCDay( ) set the Universal Time day of the week
setUTCHours( ) set the Universal Time hours
setUTCMinutes( ) set the Universal Time minutes
setUTCSeconds( ) set the Universal Time seconds
setUTCMilliseconds( ) set the Universal Time milliseconds
The following example determines how many days are left until a specific date -- in this case a birthday which occurs on December 15. The Date( ) object constructor is used to create two instances of the Date( ) object; one for today and one for the birthday. An "if" statement then checks to make sure the birthday hasn't already passed, and prints a message if not. The the time difference is obtained by subtracting today's value from the birthday value and dividing the resulting millisecond value into days. (The calculation uses Math.floor( ) which rounds a calculation down to the nearest integer value.)
Example
<SCRIPT language="javascript">
today = new Date( ); // set today's date
birthday = new Date( ); // set up the Birthday object
birthday.setMonth(11); // set birthday month to December
birthday.setDate(15); // set birthday date to the 15th
if (today.getTime( ) < birthday.getTime( ))
{ diff = birthday.getTime( ) - today.getTime( );
diff = Math.floor(diff / (1000 * 60 * 60 * 24));
document.write('There are ' + diff + ' days until December 15.');
}
</SCRIPT>
As an interesting exercise, try enhancing this script to determine if today is the birthday, or if this year's birthday has already passed (there's already code for that) and printing an appropriate message in each case.
In the next part of this series, we continue with the use of the Date( ) object methods.
Wednesday, May 5, 2010
How to convert Currency To word in Crystal report
ToWords(CDbl ({@RS}),0)
else if (CDbl ({@RS}) <= 9999999) then
ProperCase(ToWords(CDbl (Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-5)),0) + " Lac " + ToWords(CDbl (Right (replace ({@RS}, ",",""),5)),0))
else if (CDbl ({@RS}) <= 999999999) then
ProperCase(
ToWords(CDbl (Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-7)),0) + " Crore "+
ToWords(CDbl (Right(Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-5),2)),0) + " Lac " +
ToWords(CDbl (Right (replace ({@RS}, ",",""),5)),0)
)
else if (CDbl ({@RS}) <= 99999999999) then
ProperCase(
ToWords(CDbl (Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-9)),0) + " Arab "+
ToWords(CDbl (Right(Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-7),2)),0) + " Crore "+
ToWords(CDbl (Right(Left (replace ({@RS}, ",",""), LEN(replace ({@RS}, ",",""))-5),2)),0) + " Lac " +
ToWords(CDbl (Right (replace ({@RS}, ",",""),5)),0)
)
Monday, May 3, 2010
How to round to 2 decimal places using javascript
function roundNumber(num, dec)
{
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
Above javascript function can be implement as follows
var roundedNumber = roundNumber(annualPremium,2);
Friday, April 30, 2010
How to skip javascript error.
window.onerror=function(){
alert('An error has occurred!')
return true
}
</script>
Friday, April 23, 2010
Forms Authentication with Active Directory
Using Forms Authentication with Active DirectoryForms AuthenticationForms Authentication is a system in which unauthenticated requests are redirected to a Web form Upon submitting the form, and being properly verified by your application, an authorization ticket is issued by Web application, in the form of a cookie. Active DirectoryActive Directory is an essential and inseparable element of the Windows 2000 network architecture RequirementsMicrosoft Windows® 2000 BriefIn this article I'll show how to implement form authentication using Active Directory warehouse credentials. Creating the Login PageThe first thing we have to do is to create a new solution in Visual Studio 2005. On the page load event of the login page you can add the following code to display the identity domain and username if(!Page.IsPostback()) Configuring the application
Also, you must add the <authorization> tag to allow only the authenticated users have access to the application. For that go to the application's virtual directory Properties, After that a little modification in the web.config is needed. So your configuration file should looks like this one: <authentication As result of this configuration, every request directed to the application will be executed in the configured anonymous account Implementing the Active directory validationNow it is time to implement the active directory authentication code. Yow could start creating a class library with a class that implements an authentication method against AD. The connection to active directory is through LDAP. Initially, the method tries to connect with Active Directory using the provided credentials. Your class should looks like the next one using Implementing the authentication processIn this step you are going to develop the fully authentication process For the authenticated users, a form authentication credential will be created You should add on the login button event handler some code to create a new active directory validation class instance a. Authenticate the user against Activates Directory. // Path Remember that you must change the access path so that aims at the AD Server, Implementing an authentication request controllerNow the question is how the application to knows if the user is authenticated or not every time the application makes a request. You can do this procedure in the global.asax file. Finally, the GenericPrincipal object will be associated with the current HttpContext object created for each web request. using Testing the applicationWe already finished the authentication process and it is time to test it. I suggest you to debug the application so you can understand how it is working. |