Pages

Saturday 31 December 2011

Email Sending in asp.net


using System.Net;
using System.Net.Mail;

private string MailFrom = "myMail@gmail.com";
private string MailPassword = "myPassword";
public string MailSubject { get; set; }
public string MailTo { get ; set;}
public string MailBody { get; set; }
public string Attachment { get; set; }

public void SendEmail()
        { 

            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential(MailFrom, MailPassword);
            MailMessage msg = new MailMessage(MailFrom, MailTo);         
            Attachment att = new Attachment (Attachment);
            msg.Attachments.Add(att);
            msg.Subject = MailSubject;
            msg.Body = MailBody;          
            msg.IsBodyHtml = true;
            smtp.EnableSsl = true;
            smtp.Send(msg);
        }



Thursday 29 December 2011

Alert Messages for Ajaxed pages


We can use the following code for alert messages in ajaxed pages:
 

ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert(' Message....? ');", true);
 
 
 
 
 
 
 
 
 

Dynamic Calendar Extender in Ajax Control Toolkit


Here we are going to create a textbox and Ajax Calendar Extender dynamically.

TextBox textbox = new TextBox();
textbox.ID = this.ID + "Textbox";
textbox.Text = this.EditableField.TextValue;
textbox.TextChanged += new EventHandler(HandleTextboxTextChanged);
textbox.Width = new Unit(100, UnitType.Pixel);
CalendarExtender calExender = new CalendarExtender();
calExender.PopupButtonID = "Image1";
calExender.TargetControlID = textbox.ID;
this.Controls.Add(textbox);
this.Controls.Add(calExender);

The form should contain toolkit script manager.

Tuesday 8 November 2011

Preventing the use of backbutton in asp.net

We can use the javascript code below  to prevent the use of backbutton in asp.net webpages.


<script type="text/javascript">
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
</script>