PDA

View Full Version : RadioButtonList causing email error


many_tentacles
05-19-2009, 05:45 PM
Hi

I have a simplified example of a form I am trying to create to send user feedback.

It works fine unless the form is submitted without checking a radio button. Since it is not a required field, I can't work out a way around it.

Any help would be much appreciated.

Thanks


<% @Import Namespace="System.Web.Mail" %>
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="UTF-8" %>

<script runat="server">

Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

end sub

Sub btnSendFeedback_Click(sender as Object, e as EventArgs)

Dim objMM as New MailMessage()
objMM.To = "mail@address.co.uk"
objMM.From = "myform@address.co.uk"
objMM.BodyFormat = MailFormat.HTML
objMM.Priority = MailPriority.Normal
objMM.Subject = "Test email"
objMM.Body = "You selected " & question1.SelectedItem.Value & ", thanks" & _
"See you soon"


SmtpMail.SmtpServer = "localhost"

SmtpMail.Send(objMM)

response.Redirect("default3.aspx")

End Sub

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

</head>

<body>

<form runat="server">

<asp:radiobuttonlist id="question1" runat="server" CssClass="radiooptions" RepeatColumns="4" CellPadding="0" CellSpacing="0">
<asp:listitem id="answer1_1" runat="server" value="Excellent" Text="" />
<asp:listitem id="answer1_2" runat="server" value="Good" Text="" />
<asp:listitem id="answer1_3" runat="server" value="Average" Text="" />
<asp:listitem id="answer1_4" runat="server" value="Poor" Text="" />
</asp:radiobuttonlist>


<asp:Button OnClick="btnSendFeedback_Click" runat="server" Text="Submit..." ID="submitbutton" />


</form>
</body>
</html>

vinyl-junkie
05-20-2009, 04:21 AM
Something like this will work:

If (string.IsNullOrEmpty(question1.SelectedValue)) Then
objMM.Body = "You selected nothing, thanks" & _
"See you soon"
Else
objMM.Body = "You selected " & question1.SelectedItem.Value & ", thanks" & _
"See you soon"
End If