i would like to display a preloading image like spinning circle,please wait text etc on button click and show an alert message when the function complete. In my scenario on button click a code behind method is called for sending email. when sending email i would like to display preloader and when completes an alert message should be displayed. Following is my code.

protected void btnSubmit1_Click(object sender, EventArgs e)
{
    const string esender = "emailid@email.com";
    const string sp = "password";
    string bodyMessage = "";
    //string text = txtmsg.text;
    try
    {
        SmtpClient smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new System.Net.NetworkCredential(esender, sp),
            Timeout = 30000
        };
        bodyMessage = "Details of the sender\n" +
            "Name : " + txtName.Text + "\n\n" +
            "Email : " + txtemail.Text + "\n\n" +
            "Contact : " + txtNumber.Text + "\n\n" +
            "Subject : " + txtsubject.Text + "\n\n" +
            "Message : " + txtmsg.Text;
        MailMessage message = new MailMessage(esender, "receiver@gmail.com","Customer Enquiry", bodyMessage);
        smtp.Send(message);
    }
    catch (Exception ex)
    {

    }
}

and aspx code for button

<asp:Button ID="btnSubmit1" Text="Submit Message" class="btn btn-primary btn-lg"  OnClick="btnSubmit1_Click" runat="server" />

Related posts

Recent Viewed