Posted by : Anwar Hossain
Category : Mail sending in asp.net c#

Feedback form with Yes or No Option in ASP.Net C#

Dear viewers I will show how to create feedback from with radio button in ASP.Net C #. Sometimes we need to create yes or no option at the time of creating feedback from in ASP.Net C # .in this situation we can use RadioButtonList. In this tutorial I have given complete code for sending mail using RadioButtonList in ASP.Net C Sharp.

Feedback form with Yes or  No Option in ASP.Net C#

HTML

<html >

<head runat="server">

    <title></title>

    <style type="text/css">

        .style1

        {

            color: #FF3300;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div >

        <fieldset style="width: 40%; background-color: #FFF4DF;">

            <legend>Feedback</legend>

            <table cellpadding="2" cellspacing="5" >

               

                <tr>

                    <td width="80px">

                    </td>

                    <td>

                    </td>

                </tr>

                <tr>

                    <td width="80px">

                        Name<span style="color: #CC3300"> *</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtName" runat="server" Width="200px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

                            ErrorMessage="Name Required" ForeColor="#FF3300"

                            ControlToValidate="txtName"></asp:RequiredFieldValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        Subject <span class="style1">*</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtSubject" runat="server" Width="200px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

                            ErrorMessage="Subject Required" ForeColor="#FF3300"

                            ControlToValidate="txtSubject"></asp:RequiredFieldValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        E-mail<span style="color: #CC3300"> *</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtEmail" runat="server" Width="300px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"

                            ErrorMessage="Email Required" ForeColor="#FF3300"

                            ControlToValidate="txtEmail"></asp:RequiredFieldValidator>

                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"

                            ErrorMessage="Not a vailed email" ControlToValidate="txtEmail"

                            ForeColor="#FF3300"

                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">

</asp:RegularExpressionValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        Inquiry<span style="color: #CC3300"> </span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtInquiry" runat="server" Height="100px" TextMode="MultiLine" Width="400px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td>

                        Gender</td>

                    <td>

                        <asp:RadioButtonList ID="rdlGender" runat="server" RepeatDirection="Horizontal">

                            <asp:ListItem Selected="True">Male</asp:ListItem>

                            <asp:ListItem>Female</asp:ListItem>

                        </asp:RadioButtonList>

 

                        

 

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        <asp:Button ID="btnSubmit" runat="server" Text="Send" Width="100px" OnClick="btnSubmit_Click1" />

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        &nbsp;

                    </td>

                </tr>

            </table>

        </fieldset>

    </div>

    </form>

</body>

</html>

 

 

 

CODE BEHIND

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Net.Mail;

using System.Net;

using System.Drawing;

using System.IO;

 

public partial class Feedback : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

 

 

 

    private void EmailFeedback()

    {

 

        //create the mail message

        MailMessage mail = new MailMessage();

 

        //set the addresses

        mail.From = new MailAddress(txtEmail.Text.Trim());

 

        mail.To.Add("anwar@csharpexample.com");

 

        //set the content

        mail.Subject = "Enquiry Form";

 

        //Body to be displayed

        mail.Body = "<h2>" + "Enquiry from " + " " + txtName.Text + "</h2>" + "<br><br>" +

                "Subject: " + txtSubject.Text + "<br>" +

                "Email : " + txtEmail.Text.Trim() + "<br>" +

                "InQuiry: " + txtInquiry.Text.Trim() + "<br>" +

                "Gender: " + rdlGender.SelectedValue.ToString()+ "<br>" +

                "Thank You";

 

        //Attachment

 

      

 

        mail.IsBodyHtml = true;

 

        // smtp settings

        SmtpClient smtp = new SmtpClient("mail.csharpexample.com");

        NetworkCredential SMTPUserInfo = new NetworkCredential("anwar@csharpexample.com", "Abcd123adsf@");

        smtp.Credentials = SMTPUserInfo;

        smtp.Send(mail);

 

 

 

 

    }

 

    private void Clear()

    {

        txtName.Text = string.Empty;

        txtSubject.Text = string.Empty;    

        txtEmail.Text = string.Empty;  

        txtInquiry.Text = string.Empty;

       

 

    }

     

    protected void btnSubmit_Click1(object sender, EventArgs e)

    {

      

            EmailFeedback();

            lblMsg.ForeColor = Color.Green;

            Clear();

            lblMsg.Text = "Thank You for Your Inquiry";

 

       

    }

}

Out Put

yes-no-option-feedback-in-asp.net-c-Sharp



Realted Article Headline

Send mail with multiple selections in ASP.Net C #.
Feedback form with Yes or No Option in ASP.Net C#
Send mail with attachment file in ASP.Net C #
Send mail using Gmail account in ASP.Net C#.
Feedback form example in ASP.Net C#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection