7/28/08

JavaScript and Object Oriented Programming

JavaScript and Object Oriented Programming (OOP) Credits: This tutorial is written and contributed by Tim Scarfe. Edited by JavaScriptKit.com for content/ structure. Please see footnote for more information on author. JavaScript is an excellent language to write object oriented web applications. It can support OOP because it supports inheritance through prototyping as well as properties and methods. Many developers cast off JS as a suitable OOP language because they are so used to the class style of C# and Java. Many people don't realize that JavaScript supports inheritance. When you write object-oriented code it instantly gives you power; you can write code that can be re-used and that is encapsulated. What's so great about objects? Objects work so well because they act just like real life objects- objects have properties and methods. So if we were talking about a lamp, a property of it may be its height or width, say 12cm. A method of it may be to shine (an action). And when it's shining, its brightness property would be of a greater value than when it wasn't. JavaScript gives you the ability to make your own objects for your own applications. With your objects you can code in events that fire when you want them to, and the code is encapsulated. It can be initialized any amount of times. Creating objects using new Object() There are several ways to create objects in JavaScript, and all of them have their place. The simplest way is to use the new operator, specifically, new Object(): We define a custom object "person," then add to it its own properties and method afterwards. In this case, the custom method merely initializes two more properties. Creating objects using Literal Notation Another inline way of defining an object is via literal notation. Supported in JavaScript1.2 and above, it's a more robust form of creating an object on the fly: Literal notion can contain arrays or arbitrary JavaScript expressions or values. While using the new operator or literal notion to create a custom object is both simple and logical, the biggest shortcoming is that the result is NOT reusable- we cannot easily initialize different versions of the created object. For example with the first demonstration above, if the person's name is not "Tim Scarfe", we would need to redefine our entire object just to accommodate this change.

Sending e-mail with attachments from an ASP.NET page

The task of sending e-mails has become much easier in ASP.NET. In previous versions of ASP we either used a third party component or the limited functionality of CDONTS component for sending emails. The .NET framework provides simpler but powerful class libraries for sending emails. These classes are in the System.Web.Mail Namespace. Following table lists the classes and their use : Class Purpose MailAttachment To construct an email attachment. MailMessage To construct an email message. SmtpMail To send an email attachment using the SMTP mail service. High-end commercial email component : i. AspEmail : Most feature-rich mailing component. Supports message queueing, embedded images, secure mail, authentication. Read more. In order to access these classes we have to import the System.Web.Mail namespace within our ASP.NET page using the import directive as shown below : <% @ Import NameSpace = "System.Web.Mail" %> Then we construct an email message by creating an Instance of the MailMessage class as shown below : MailMessage MyMail = new MailMessage(); The MailMessage class has various properties which need to be set before sending emails. Following table shows some of the important properties of the MailMessage class : Property Description Attachments List of attachments that is sent with the email. Body Body of the email message. From Email address of the sender. Subject Subject line of the email message. To Email address of the recipient. To send an attachment with email we need to create an instance of the MailAttachment class. We pass the full path of the file to be attached as an argument to the constructor of MailAttachment class as shown below : MailAttachment MyAttachment = new MailAttachment("C:\\My Folder\\MyFile.txt"); Note : The file name passed should be valid file which exists on the server. This MailAttachment instance is then attached to the mail by using the Attachment property of the Mail class as shown below : MyMail.Attachments.Add(MyAttachment); Finally we send the email using the Send() method of the SmtpMail Class as shown below : SmtpMail.Send(MyMail);

Bride Mehndi Design

Bride Mehndi Design

Bride Mehndi Design

funny

rose

Importance of friendship

BramhaKAMAL

Flower

BramhaKAMAL

BramhaKAMAL

Bride Mehndi Design

Bride Mehndi Design