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
  1. public void SendMail()
  2. {
  3. try
  4. {
  5. string fromMail = "ENTER FROM MAIL ADDRESS";
  6. string toMail= "ENTER TO MAIL ADDRESS";
  7. string smtpServer="ENTER SMTP SERVER ADDRESS HERE";
  8. string subject="ENTER SUBJECT HERE";
  9. string bodyMessage="ENTER BODY MESSAGE HERE";
  10. string password="ENTER YOUR PASSWORD HERE";
  11. MailMessage MyMailMessage = new MailMessage();
  12. MyMailMessage.From = new MailAddress(fromMail );
  13. MyMailMessage.To.Add(toMail);
  14. MyMailMessage.Subject = subject;
  15. MyMailMessage.Body = bodyMessage;
  16. MyMailMessage.IsBodyHtml = false;
  17. OpenFileDialog ofd = new OpenFileDialog();
  18. ofd.ShowDialog();
  19. Attachment attachment = new Attachment(ofd.FileName);
  20. MyMailMessage.Attachments.Add(attachment);
  21. SmtpClient client = new SmtpClient(smtpServer);
  22. client.Port = 25;
  23. client.Credentials = new System.Net.NetworkCredential(fromMail , password);
  24. client.EnableSsl = true;
  25. client.Send(MyMailMessage);
  26. }
  27. catch (Exception ex)
  28. {
  29. throw ex;
  30. }
  31. }
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
  1. public void SendMail()
  2. {
  3. try
  4. {
  5. string fromMail = "ENTER FROM MAIL ADDRESS";
  6. string toMail= "ENTER TO MAIL ADDRESS";
  7. string smtpServer="ENTER SMTP SERVER ADDRESS HERE";
  8. string subject="ENTER SUBJECT HERE";
  9. string bodyMessage="ENTER BODY MESSAGE HERE";
  10. string password="ENTER YOUR PASSWORD HERE";
  11. MailMessage MyMailMessage = new MailMessage();
  12. MyMailMessage.From = new MailAddress(fromMail );
  13. MyMailMessage.To.Add(toMail);
  14. MyMailMessage.Subject = subject;
  15. MyMailMessage.Body = bodyMessage;
  16. MyMailMessage.IsBodyHtml = false;
  17. SmtpClient client = new SmtpClient(smtpServer);
  18. client.Port = 25;
  19. client.Credentials = new System.Net.NetworkCredential(fromMail , password);
  20. client.EnableSsl = true;
  21. client.Send(MyMailMessage);
  22. }
  23. catch (Exception ex)
  24. {
  25. throw ex;
  26. }
  27. }
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.