Sunday, December 2, 2012

What are all the JavaScript events

What is event?

In a simple word, Events are user actions. For example when a user click a button in a webpage that should trigger some actions that perform some function execution. The following is the JavaScript events and when its occurs.

JavaScript Events

onabort       : This event occurs  when the user aborts an action
onblur        : This event occurs  when an element loses the input focus
onchange      : This event occurs  when data in a control, such as a text field changes
onclick       : This event occurs  when the user clicks an element
ondblclick    : This event occurs  when the user double-clicks an element
onkeyup       : This event occurs  when the user releases a key
onload        : This event occurs  when the page loads
onmousedown   : This event occurs  when the user presses down a mouse button
onmousemove   : This event occurs  when the user moves the mouse
onmouseout    : This event occurs  when the user moves the cursor away from an element
onmouseover   : This event occurs  when the user moves the cursor over an element
ondragdrop    : This event occurs  when the user drags and drops an element
onerror       : This event occurs  when there’s been a JavaScript error
onfocus       : This event occurs  when an element gets the focus
onkeydown     : This event occurs  when the user presses down on a key
onkeypress    : This event occurs  when the user presses a key
onmouseup     : This event occurs  when the user releases a mouse button
onreset       : This event occurs  when the user clicks a Reset button
onresize      : This event occurs  when the user re sizes an element or a page
onsubmit      : This event occurs  when the user clicks a Submit button
onunload      : This event occurs  when the browser unloads a page and moves to another page

Example:


 <html>  
 <head>  
 <script>  
    function displayText()  
    {  
      alert('Hi User');  
    }  
 </script>  
 </head>  
 <body>  
 <h1 onclick="displayText()">Click on this text!</h1>  
 </body>  
 </html>  

Thursday, November 29, 2012

How to send smtp mail with attachment using CSharp ( c#)

In this post we going to see how to add a attachment in SMTP mail using CSharp code. A simple csharp code is shown below
 public void SendMail()  
 {  
   try  
   {  
     string fromMail = "ENTER FROM MAIL ADDRESS";  
     string toMail= "ENTER TO MAIL ADDRESS";  
     string smtpServer="ENTER SMTP SERVER ADDRESS HERE";  
     string subject="ENTER SUBJECT HERE";  
     string bodyMessage="ENTER BODY MESSAGE HERE";  
     string password="ENTER YOUR PASSWORD HERE";  
     MailMessage MyMailMessage = new MailMessage();  
     MyMailMessage.From = new MailAddress(fromMail );  
     MyMailMessage.To.Add(toMail);  
     MyMailMessage.Subject = subject;  
     MyMailMessage.Body = bodyMessage;  
     MyMailMessage.IsBodyHtml = false;  
     OpenFileDialog ofd = new OpenFileDialog();  
     ofd.ShowDialog();  
     Attachment attachment = new Attachment(ofd.FileName);  
     MyMailMessage.Attachments.Add(attachment);  
     SmtpClient client = new SmtpClient(smtpServer);  
     client.Port = 25;  
     client.Credentials = new System.Net.NetworkCredential(fromMail , password);  
     client.EnableSsl = true;  
     client.Send(MyMailMessage);  
   }  
   catch (Exception ex)  
   {  
     throw ex;  
   }  
 }  
In the above code i have used OpenFileDialog to let the user to select the attachment to send through mail. Note: You have to add System.Net.Mail namespace to make this code work.

How to send mail using CSharp ( c# ) code

In this post we going to see how to send a SMTP mail using CSharp code. A simple csharp code is shown below
 public void SendMail()  
 {  
   try  
   {  
     string fromMail = "ENTER FROM MAIL ADDRESS";  
     string toMail= "ENTER TO MAIL ADDRESS";  
     string smtpServer="ENTER SMTP SERVER ADDRESS HERE";  
     string subject="ENTER SUBJECT HERE";  
     string bodyMessage="ENTER BODY MESSAGE HERE";  
     string password="ENTER YOUR PASSWORD HERE";  
     MailMessage MyMailMessage = new MailMessage();  
     MyMailMessage.From = new MailAddress(fromMail );  
     MyMailMessage.To.Add(toMail);  
     MyMailMessage.Subject = subject;  
     MyMailMessage.Body = bodyMessage;  
     MyMailMessage.IsBodyHtml = false;  
     SmtpClient client = new SmtpClient(smtpServer);  
     client.Port = 25;  
     client.Credentials = new System.Net.NetworkCredential(fromMail , password);  
     client.EnableSsl = true;  
     client.Send(MyMailMessage);  
   }  
   catch (Exception ex)  
   {  
     throw ex;  
   }  
 }  
if you want to send mail using Gmail SMTP use the smtp.gmail.com SMTP Server and the port should be 25.

Note: You have to add System.Net.Mail namespace to make this code work.