Hi RichardSa,
The simplest way is to use RadioButtonList with RequiredFieldValidator.
If you want a group radiobutton instead RadioButtonList, you have to use CustomValidator with OnServerValidate event.
Check this example. Now please take its reference and correct your code.
HTML
<div>
<div class="text-center" style="width: auto; height: auto; font-family: Nunito;">
<div class="centee">
<br />
<label id="qlabel">How will you like to take your tour of our school?</label><br />
<asp:RadioButton runat="server" ID="radiobtnA1" GroupName="radiobtnA" AutoPostBack="False" />
<label for="radiobtnA1">By Bus</label><br />
<asp:RadioButton runat="server" ID="radiobtnA2" GroupName="radiobtnA" AutoPostBack="False" />
<label for="radiobtnA2">By walking</label><br />
<asp:RadioButton runat="server" ID="radiobtnA3" GroupName="radiobtnA" AutoPostBack="False" />
<label for="radiobtnA3">I don't like Tours</label>
<asp:CustomValidator ID="cvSchool" runat="server" Display="Dynamic" ErrorMessage="Please choose tour type"
OnServerValidate="OnServerValidate1"></asp:CustomValidator>
<br />
<br />
<label id="Labl">Will you have time to learn?</label><br />
<asp:RadioButton runat="server" ID="radiobtnB1" GroupName="radiobtnB" AutoPostBack="False" />
<label for="radiobtnB1">Yes, I have time</label><br />
<asp:RadioButton runat="server" ID="radiobtnB2" GroupName="radiobtnB" AutoPostBack="False" />
<label for="radiobtnB2">No, I'm a very busy person</label><br />
<asp:RadioButton runat="server" ID="radiobtnB3" GroupName="radiobtnB" AutoPostBack="False" />
<label for="radiobtnB3">I'm busy but I can create time</label>
<asp:CustomValidator ID="cvLearn" runat="server" Display="Dynamic" ErrorMessage="Please choose learn type"
OnServerValidate="OnServerValidate2"></asp:CustomValidator>
<br />
<br />
<label id="Labla">How much time can you dedicate to learn?</label><br />
<asp:RadioButton runat="server" ID="radiobtnC1" GroupName="radiobtnC" AutoPostBack="False" />
<label for="radiobtnC1">30Mins - 1Hr</label><br />
<asp:RadioButton runat="server" ID="radiobtnC2" GroupName="radiobtnC" AutoPostBack="False" />
<label for="radiobtnC2">1Hr - 3Hrs</label><br />
<asp:RadioButton runat="server" ID="radiobtnC3" GroupName="radiobtnC" AutoPostBack="False" />
<label for="radiobtnC3">3Hrs - 6Hrs</label>
<asp:CustomValidator ID="cvLearnTime" runat="server" Display="Dynamic" ErrorMessage="Please choose learn time"
OnServerValidate="OnServerValidate3"></asp:CustomValidator>
<br />
<br />
</div>
</div>
<div class="container-fluid">
<br />
<label for="txtPassword" style="font-weight: 600;">First Name</label>
<asp:TextBox ID="txtName" runat="server" CssClass="form-control" Font-Size="10pt" placeholder="First Name" />
<label style="font-weight: 600;">Last Name</label>
<asp:TextBox ID="textLast" CssClass="form-control" runat="server" Font-Size="10pt" placeholder="Last Name"></asp:TextBox>
<label style="font-weight: 600;">WhatsApp Number</label>
<asp:TextBox ID="textNumber" CssClass="form-control" runat="server" Font-Size="10pt" placeholder="WhatsAPP Number"></asp:TextBox>
<label style="font-weight: 600;">Email Address</label>
<asp:TextBox ID="textemail" CssClass="form-control" runat="server" Font-Size="10pt" placeholder="Email Address"></asp:TextBox>
<br />
<asp:Button ID="btnreg" runat="server" Text="Start My Training" class="btn btn-primary navbar-btn" OnClick="btnreg_Click" />
<asp:Label ID="lblMessage" Width="100%" runat="server" Font-Size="Small"></asp:Label>
</div>
</div>
Namespaces
C#
using System.Configuration;
using System.Net;
using System.Net.Configuration;
using System.Net.Mail;
VB.Net
Imports System.Configuration
Imports System.Net
Imports System.Net.Configuration
Imports System.Net.Mail
Code
C#
protected void OnServerValidate1(object source, ServerValidateEventArgs args)
{
args.IsValid = radiobtnA1.Checked || radiobtnA2.Checked || radiobtnA3.Checked;
}
protected void OnServerValidate2(object source, ServerValidateEventArgs args)
{
args.IsValid = radiobtnB1.Checked || radiobtnB2.Checked || radiobtnB3.Checked;
}
protected void OnServerValidate3(object source, ServerValidateEventArgs args)
{
args.IsValid = radiobtnC1.Checked || radiobtnC2.Checked || radiobtnC3.Checked;
}
protected void btnreg_Click(object sender, EventArgs e)
{
if (txtName.Text != "" & textLast.Text != "" & textNumber.Text != "" & textemail.Text != "")
{
//Validate is successful.
if (Page.IsValid)
{
SmtpSection smtpsection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailsettings/smtp");
using (MailMessage mm = new MailMessage(smtpsection.From, "mannyrchrd@gmail.com"))
{
mm.Subject = "follow up";
mm.Body = "name: " + txtName.Text + " " + textLast.Text + "<br /><br />email: " + textemail.Text + "<br /><br />mobile number: " + textNumber.Text + "<br /><br />"
+ string.Format("how much would you like to earn in order to make this worth your time? <br />{0}", radiobtnA1.Checked ? "10k - 100k" : (radiobtnA2.Checked ? "100k - 500k" : (radiobtnA3.Checked ? "500k - 1m" : ""))) + "<br /><br />"
+ string.Format("will you have time to learn? <br />{0}", radiobtnB1.Checked ? "yes, i have time" : (radiobtnB2.Checked ? "no, i'm a very busy person" : (radiobtnB3.Checked ? "i'm busy but i can create time" : ""))) + "<br /><br />"
+ string.Format("how much time can you dedicate each day in order to achieve your monthly goal? <br />{0}", radiobtnC1.Checked ? "30mins - 1hr" : (radiobtnC2.Checked ? "1hr - 3hrs" : (radiobtnC3.Checked ? "3hrs - 6hrs" : "")));
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = smtpsection.Network.Host;
smtp.EnableSsl = smtpsection.Network.EnableSsl;
NetworkCredential networkcred = new NetworkCredential(smtpsection.Network.UserName, smtpsection.Network.Password);
smtp.UseDefaultCredentials = smtpsection.Network.DefaultCredentials;
smtp.Credentials = networkcred;
smtp.Port = smtpsection.Network.Port;
smtp.Send(mm);
}
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Thank you for submitting your data, you will be notified soon.')", true);
}
else
{
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "*Please Choose an answer";
}
}
else
{
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "*All Fields Are Required*";
}
}
VB.Net
Protected Sub OnServerValidate1(ByVal source As Object, ByVal args As ServerValidateEventArgs)
args.IsValid = radiobtnA1.Checked OrElse radiobtnA2.Checked OrElse radiobtnA3.Checked
End Sub
Protected Sub OnServerValidate2(ByVal source As Object, ByVal args As ServerValidateEventArgs)
args.IsValid = radiobtnB1.Checked OrElse radiobtnB2.Checked OrElse radiobtnB3.Checked
End Sub
Protected Sub OnServerValidate3(ByVal source As Object, ByVal args As ServerValidateEventArgs)
args.IsValid = radiobtnC1.Checked OrElse radiobtnC2.Checked OrElse radiobtnC3.Checked
End Sub
Protected Sub btnreg_Click(ByVal sender As Object, ByVal e As EventArgs)
If txtName.Text<> "" And textLast.Text<> "" And textNumber.Text<> "" And textemail.Text<> "" Then
'Validate is successful.
If Page.IsValid Then
Dim smtpsection As SmtpSection = CType(ConfigurationManager.GetSection("system.net/mailsettings/smtp"), SmtpSection)
Using mm As MailMessage = New MailMessage(smtpsection.From, "mannyrchrd@gmail.com")
mm.Subject = "follow up"
mm.Body = "name: " & txtName.Text & " " + textLast.Text & "<br /><br />email: " + textemail.Text & "<br /><br />mobile number: " + textNumber.Text & "<br /><br />"
& String.Format("how much would you like to earn in order to make this worth your time? <br />{0}", If(radiobtnA1.Checked, "10k - 100k", (If(radiobtnA2.Checked, "100k - 500k", (If(radiobtnA3.Checked, "500k - 1m", "")))))) & "<br /><br />"
& String.Format("will you have time to learn? <br />{0}", If(radiobtnB1.Checked, "yes, i have time", (If(radiobtnB2.Checked, "no, i'm a very busy person", (If(radiobtnB3.Checked, "i'm busy but i can create time", "")))))) & "<br /><br />"
& String.Format("how much time can you dedicate each day in order to achieve your monthly goal? <br />{0}", If(radiobtnC1.Checked, "30mins - 1hr", (If(radiobtnC2.Checked, "1hr - 3hrs", (If(radiobtnC3.Checked, "3hrs - 6hrs", ""))))))
mm.IsBodyHtml = True
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = smtpsection.Network.Host
smtp.EnableSsl = smtpsection.Network.EnableSsl
Dim networkcred As NetworkCredential = New NetworkCredential(smtpsection.Network.UserName, smtpsection.Network.Password)
smtp.UseDefaultCredentials = smtpsection.Network.DefaultCredentials
smtp.Credentials = networkcred
smtp.Port = smtpsection.Network.Port
smtp.Send(mm)
End Using
ClientScript.RegisterStartupScript(Me.GetType(), "", "alert('Thank you for submitting your data, you will be notified soon.')", True)
Else
lblMessage.Visible = True
lblMessage.ForeColor = System.Drawing.Color.Red
lblMessage.Text = "*Please Choose an answer"
End If
Else
lblMessage.Visible = True
lblMessage.ForeColor = System.Drawing.Color.Red
lblMessage.Text = "*All Fields Are Required*"
End If
End Sub
Screenshot