Interesting Problem with form validation

  • Thread starter Thread starter Rowena
  • Start date Start date
R

Rowena

I have a form for data entry and use validators to validate some of the
fields. I am having a problem with one part of this form.

I have a series of checkboxes (checkboxlist) that when a user clicks on one
it populates a readonly textbox with a value. I also have another seperate
checkbox that also adds a value to that same textbox. I have a
requiredfieldvalidator that validates the textbox. That functionality seems
to work fine until I try to submit the form.

If I check any of the checkboxes in the checkbox list the form submits. If I
only check the other stand-alone checkbox the textbox clears and the
requiredfieldvalidator fires and tells me the textbox is required.

I have no idea what is causing the textbox to clear when I hit submit and
why it doesn't happen when one of the checkbox list checkboxes is checked and
why it does when only the stand-alone checkbox is checked.

I will paste html, code behind below....
 
Form.aspx:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="PermitApplication_Form.aspx.vb" Inherits="PermitApplication_Form"%>
<%@ Register TagPrefix="my" Namespace="MyControls" %>
<%=""%>
<!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 runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Functions.js"></script>
<title>RDOS Burning Permit Application Form</title>
<script type="text/javascript">
function CustomValidatorAgree_ClientValidate(sender, args) {
args.IsValid =
document.getElementById("fvMain_chkRulesAndRegs").checked;
}

function txtBurnDescriptionOther_onkeydown() {
var textbox =
document.getElementById("fvMain_txtBurnDescriptionOther");
var checkbox =
document.getElementById("fvMain_chkBurnDescriptionOther");
if (textbox.text != "") {
checkbox.disabled = false;
} else {
checkbox.disabled = true;
}
}

function chkBurnDescriptionOther_onclick() {
var checkbox =
document.getElementById("fvMain_chkBurnDescriptionOther");
if (checkbox.checked == true) {
var textbox =
document.getElementById("fvMain_txtBurnDescriptionOther");
var value = textbox.value

if (value.trim() == "") {
alert("Enter a burn material");
checkbox.checked = false;
} else {
var txtBurnDescription =
document.getElementById("fvMain_Burn_Description");
var tempComment = txtBurnDescription.value;
tempComment = tempComment.trim();
tempComment = tempComment + "\r\n" + value
txtBurnDescription.value = tempComment.trim();
checkbox.disabled = true;
textbox.disabled = true;
}
}
}
</script>
</head>
<body>
<div>
<br />
<noscript>Your browser does not support JavaScript!</noscript>
<h2 style="text-align:center">RDOS Burning Permit Request Form</h2>
<hr/>
<br/>
<form runat="server" id="PermitApplicationForm">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FormView ID="fvMain" DefaultMode="Insert"
runat="server" DataKeyNames="ID" DataSourceID="sdsMain" EmptyDataText="No
records found." AllowPaging="True" PagerSettings-Mode="NextPreviousFirstLast"
PagerSettings-Position="Top" BorderStyle="Double">
<editItemTemplate>
<fieldset>
<legend>Contact Information</legend>
<p>Fields marked with an asterisk (<span
style="color:Red">*</span>) are required.</p>
<table>
<tr>
<td>
First Name:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvFirstName" ControlToValidate="First_Name" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
<td>
Last Name:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvLastName" ControlToValidate="Last_Name" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server"
id="First_Name" Width="200" maxlength="100" />
</td>
<td>
<asp:TextBox runat="server"
id="Last_Name" Width="200" maxlength="100" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">
Please fill in property owner's name
if not the same as above.<span style="color:Red">*</span>
</td>
</tr>
<tr>
<td>
Owner's First Name:
</td>
<td>
Owner's Last Name:
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server"
id="Owner_First_Name" Width="200" maxlength="100" />
</td>
<td>
<asp:TextBox runat="server"
id="Owner_Last_Name" Width="200" maxlength="100" />

</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">
Mailing Address:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvMailingAddress" ControlToValidate="Mailing_Address" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Mailing_Address" Width="200" maxlength="100" TextMode="multiline" />
</td>
</tr>
<tr>
<td colspan="2">
City/Town:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvCity" ControlToValidate="City" Text="Required!" runat="server"
ValidationGroup="main" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="City" Width="200" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="2">
Postal Code:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvPostalCode" ControlToValidate="Postal_Code" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Postal_Code" Width="200" maxlength="30" />
</td>
</tr>
<tr>
<td colspan="2">
Phone 123-123-1234:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvPhone" ControlToValidate="Phone" Text="Required!" runat="server"
ValidationGroup="main" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Phone" Width="200" maxlength="30" />
</td>
</tr>
<tr>
<td colspan="2">
Alternative Phone:
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Alt_Phone" Width="200" maxlength="30" />
</td>
</tr>
<tr>
<td colspan="2">
Cell Phone:
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Cell_Phone" Width="200" maxlength="30" />
</td>
</tr>
<tr>
<td colspan="2">
Fax:
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server" id="Fax"
Width="200" maxlength="30" />
</td>
</tr>
<tr>
<td colspan="2">
Email:
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Email" Width="200" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="2">
Primfolio (00000000.000):<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvPrimfolio" ControlToValidate="Primfolio" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox runat="server"
id="Primfolio" Width="200" maxlength="50" />
</td>
</tr>
</table>
<table>
<tr>
<td>
Property Type:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvPropertyTypeRequired" ControlToValidate="rblPropertyType"
Text="Required!" runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList
id="rblPropertyType" runat="server" DataValueField="PropertyType"
DataTextField="PropertyType" RepeatDirection="Horizontal"
DataSourceID="sdsPropertyType" />
</td>
</tr>
</table>
</fieldset>
<br/>
<fieldset>
<legend>Burn Information</legend>
<table>
<tr>
<td>
Year:<span style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvYear" ControlToValidate="Year" Text="Required!" runat="server"
ValidationGroup="main" />
</td>
<td>
<asp:DropDownList runat="server"
ID="Year" DataSourceID="sdsYear" DataTextField="Year" DataValueField="Year"/>
</td>
</tr>
</table>
<table>
<tr>
<td>
Fire Protection Area:<span
style="color:Red">*</span>
<asp:RequiredFieldValidator
ID="rfvFireProtectionArea" ControlToValidate="Fire_Protection_Area"
Text="Required!" runat="server" ValidationGroup="main" />
</td>
<td>
<asp:DropDownList runat="server"
id="Fire_Protection_Area" datasourceid="sdsFireProtectionArea"
DataValueField="Fire_Prot_Area" DataTextField="Fire_Prot_Area" />
</td>
</tr>
</table>
<table>
<tr>
<td>
<label for="Burn_Address">Address of
Burn Location:<span style="color:Red">*</span></label>
<asp:RequiredFieldValidator
ID="rfvBurn_Address" ControlToValidate="Burn_Address" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server"
id="Burn_Address" Height="112px" Width="289px" MaxLength="100"
TextMode="multiline" />
</td>
</tr>
</table>
<table>
<tr>
<td style="vertical-align:text-top"
colspan="2">
<label for="Burn_Description">What
you are planning to burn:<span style="color:Red">*</span></label>
<asp:RequiredFieldValidator
ID="rfvBurnDescription" ControlToValidate="Burn_Description" Text="Required!"
runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td style="vertical-align:text-top">
<asp:UpdatePanel
ID="upBurnDescriptionCBL" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:CheckBoxList
id="cblBurnDescription" runat="server" DataValueField="BurnDescription"
DataTextField="DescriptionAndComment" DataSourceID="sdsBurnDescription"
OnSelectedIndexChanged="cblBurnDescription_SelectedIndexChanged"
AutoPostBack="true" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="cblBurnDescription" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:CheckBox
ID="chkBurnDescriptionOther" runat="server" Text="Other" onclick="return
chkBurnDescriptionOther_onclick()" />
<asp:TextBox runat="server"
id="txtBurnDescriptionOther" Text=""
onkeydown="javascript:txtBurnDescriptionOther_onkeydown();" MaxLength="200"
/>
</td>
<td style="vertical-align:text-top">
<asp:UpdatePanel
ID="upBurnDescrptionTXT" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server"
id="Burn_Description" readonly="True" Height="112px" Width="289px"
TextMode="multiline" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Button runat="server"
id="BurnDescriptionClear" Text="Clear" OnClick="BurnDescriptionClear_onClick"
/>
</td>
</tr>
</table>
</fieldset>
<table>
<tr>
<td>
<my:ValidatedCheckBox runat="server"
id="chkRulesAndRegs" text="I have read and understood the Rules and
Regulations." />
<a
href="http://www.rdosmaps.bc.ca/min_bylaws/finance/BurningPermit/Regulations.pdf" target="_blank">Rules and Regulations</a>
<asp:CustomValidator ID="cvRulesAndRegs"
Text="Required!" runat="server" ValidationGroup="main"
OnServerValidate="CustomValidatorAgree_ServerValidate"
ClientValidationFunction="CustomValidatorAgree_ClientValidate"
ControlToValidate="chkRulesAndRegs" />
</td>
</tr>
<tr>
<td>
<label
for="ApplicationSubmitedBy">Application submit by:<span
style="color:Red">*</span></label>
<asp:RequiredFieldValidator
ID="rfvApplicationSubmitedBy" ControlToValidate="ApplicationSubmitedBy"
Text="Required!" runat="server" ValidationGroup="main" />
</td>
</tr>
<tr>
<td>
<asp:DropDownList runat="server"
ID="ApplicationSubmitedBy" DataSourceID="sdsSubmitBy"
DataTextField="StaffName" DataValueField="StaffName" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="InsertButtonMain"
CommandName="Insert" runat="server" Text="Submit" ValidationGroup="main"
OnClick="InsertButton_OnClick" />
<input type="reset" value="Reset"/>
</td>
</tr>
</table>
</editItemTemplate>
</asp:FormView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="fvMain"
EventName="ItemInserting" />
</Triggers>
</asp:UpdatePanel>
<table>
<tr>
<td colspan="3">
<a href="BurningPermitMain.aspx">Burning Permit Home</a>

</td>
</tr>
</table>
</div>
</form>
<asp:SqlDataSource ID="sdsMain" runat="server" ConnectionString="<%$
ConnectionStrings:RDOS_AppConnectionString %>"
InsertCommand = "INSERT INTO BurningPermitMain (BPID, FirstName,
LastName, StreetAddress, City, PostalCode, PhoneNumber, AltPhone, CellPhone,
Fax, Email, FireProtectionArea, Description, ApplicationDate, OwnerFirstName,
OwnerLastName, Primfolio, BurnLocationAddress, ApplicationSubmitedBy,
PropertyType) VALUES (@BPID,@Firstname, @LastName, @MailingAddress, @City,
@PostalCode, @Phone, @AltPhone, @CellPhone, @Fax, @Email,
@FireProtectionArea, @BurnDescription, @ApplicationDate, @OwnerFirstName,
@OwnerLastName, @Primfolio, @BurnLocationAddress, @ApplicationSubmitedBy,
@PropertyType)" >
<InsertParameters>
<asp:Parameter Name="BPID" Type="Int64" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="MailingAddress" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="AltPhone" Type="String" />
<asp:Parameter Name="CellPhone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FireProtectionArea" Type="String" />
<asp:Parameter Name="BurnDescription" Type="String" />
<asp:Parameter Name="ApplicationDate" Type="DateTime" />
<asp:Parameter Name="OwnerFirstName" Type="String" />
<asp:Parameter Name="OwnerLastName" Type="String" />
<asp:Parameter Name="Primfolio" Type="String" />
<asp:Parameter Name="BurnLocationAddress" Type="String" />
<asp:Parameter Name="ApplicationSubmitedBy" Type="String" />
<asp:Parameter Name="PropertyType" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="sdsPropertyType"
ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>"
SelectCommand="SELECT DISTINCT PropertyType FROM BurningPermitPropertyTypes
ORDER BY PropertyType" />
<asp:SqlDataSource runat="server" ID="sdsYear" ConnectionString="<%$
ConnectionStrings:RDOS_AppConnectionString %>" SelectCommand=" SELECT null AS
Year UNION SELECT Year(GetDate()) - 1 AS Year UNION SELECT Year(GetDate()) AS
Year UNION SELECT Year(GetDate()) + 1 AS Year" />
<asp:SqlDataSource runat="server" ID="sdsFireProtectionArea"
ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>"
SelectCommand="SELECT DISTINCT Fire_Prot_Area FROM BurningInfo UNION SELECT
null AS Fire_Prot_Area ORDER BY Fire_Prot_Area" />
<asp:SqlDataSource runat="server" ID="sdsBurnDescription"
ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>"
SelectCommand="SELECT BurnDescription AS BurnDescription, BurnDescription + '
' + Comment AS DescriptionAndComment FROM BurningPermitBurnDescription ORDER
BY BurnDescription" />
<asp:SqlDataSource runat="server" ID="sdsSubmitBy" ConnectionString="<%$
ConnectionStrings:RDOS_AppConnectionString %>" SelectCommand="SELECT DISTINCT
StaffName FROM BurningPermitStaff UNION SELECT '' AS StaffName ORDER BY
StaffName" />
</div>
</body>
</html>
 
Form.aspx.vb:

Option Explicit On
Option Strict On

Imports System.Data
Imports System.Data.SqlClient

Partial Class PermitApplication_Form
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).InputAttributes.Add("disabled", "disabled")
End Sub

Protected Sub cblBurnDescription_SelectedIndexChanged()
If CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).SelectedIndex > -1 Then
Dim i As Integer
Dim sBurnDescription As String = ""
For i = 0 To CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items.Count - 1
If CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Selected Then
sBurnDescription &=
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Value.ToString & vbNewLine
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Enabled = False
End If
Next
If (CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).Checked = True) Then
sBurnDescription &=
CType(fvMain.FindControl("txtBurnDescriptionOther"), TextBox).Text
End If
CType(fvMain.FindControl("Burn_Description"), TextBox).Text =
sBurnDescription
CType(fvMain.FindControl("upBurnDescrptionTXT"),
UpdatePanel).Update()
End If
End Sub

Protected Sub BurnDescriptionClear_onclick()
CType(fvMain.FindControl("Burn_Description"), TextBox).Text = ""
Dim elem As Object = PermitApplicationForm.Controls
For i = 0 To CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items.Count - 1
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Selected = False
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Enabled = True
Next
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).Checked = False
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).InputAttributes.Add("disabled", "disabled")
CType(fvMain.FindControl("txtBurnDescriptionOther"), TextBox).Text =
""
End Sub

Protected Sub CustomValidatorAgree_ServerValidate(ByVal src As Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim cv As CustomValidator
cv = CType(fvMain.FindControl("cvRulesAndRegs"), CustomValidator)
Dim chk As CheckBox
chk = CType(fvMain.FindControl("chkRulesAndRegs"), CheckBox)
Dim boolIsChecked As Boolean
boolIsChecked = chk.Checked
cv.IsValid = boolIsChecked
End Sub

Protected Function DeterminBPID(ByVal oCon As SqlConnection, ByVal sYear
As String) As Integer
Dim sSQL As String
Dim iBPID As Integer
Try
Dim temp1, temp2 As Integer
temp1 = CInt(CStr(sYear) & "0001")
temp2 = CInt(CStr(sYear) & "9999")
sSQL = "SELECT MAX(BPID) AS [MaxBPID] FROM BurningPermitMain
WHERE BPID >= @BPID1 And BPID <= @BPID2"
Dim oCmd As New Data.SqlClient.SqlCommand
oCmd.Connection = oCon
oCmd.CommandText = sSQL
oCmd.Parameters.AddWithValue("@BPID1", temp1)
oCmd.Parameters.AddWithValue("@BPID2", temp2)

If Not IsDBNull(oCmd.ExecuteScalar()) Then
iBPID = CInt(oCmd.ExecuteScalar())
iBPID += 1
Else
iBPID = CInt(CStr(sYear) & "0001")
End If

oCmd = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication:Selecting BPID)."
Exit Function
End Try
Return iBPID
End Function

Protected Sub sdsMain_Inserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
sdsMain.Inserting
'Start a transaction so we can find the ID of the inserted value
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim InsertTransaction As SqlTransaction

cmd = CType(e.Command, SqlCommand)
con = cmd.Connection
con.Open()
InsertTransaction = con.BeginTransaction
cmd.Transaction = InsertTransaction
End Sub

Protected Sub sdsMain_Inserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
sdsMain.Inserted
Dim cmd As SqlCommand
Dim InsertTransaction As SqlTransaction
Dim iID As Integer

cmd = CType(e.Command, SqlCommand)
InsertTransaction = cmd.Transaction
cmd.CommandText = "SELECT @@IDENTITY AS [ID]"

iID = CInt(cmd.ExecuteScalar().ToString)
InsertTransaction.Commit()

sdsMain.SelectParameters.Add("ID", CStr(iID))
sdsMain.SelectParameters("ID").DefaultValue = CStr(iID)

'fvMain.ChangeMode(FormViewMode.Edit)
'fvMain.DefaultMode = FormViewMode.Edit

Dim iBPID As Integer
Try
Dim sConnectString, sSQL As String
Dim oCon As New SqlConnection
Dim oCmd As New SqlCommand

sConnectString =
System.Configuration.ConfigurationManager.ConnectionStrings("RDOS_AppConnectionString").ToString
oCon.ConnectionString = sConnectString
oCon.Open()
sSQL = "SELECT BPID FROM BurningPermitMain WHERE ID = @ID"
oCmd = New Data.SqlClient.SqlCommand(sSQL, oCon)
oCmd.Parameters.AddWithValue("@ID", iID)
iBPID = CInt(oCmd.ExecuteScalar)
oCon.Close()
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page.
'"An error occured with this application
(PermitApplication:Selecting new BPID)."
Exit Sub
End Try

'TODO:this doesn't work, must set BPID then submit form
Response.Redirect("TrackPermit.aspx?BPID=" & iBPID)
End Sub

Protected Sub InsertButton_OnClick()
Dim sConnectString, sSQL As String
Dim oCon As New SqlConnection

sConnectString =
System.Configuration.ConfigurationManager.ConnectionStrings("RDOS_AppConnectionString").ToString
Try
oCon.ConnectionString = sConnectString
oCon.Open()
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page.
'"An error occured with this application
(PermitApplication:Opening Database Connection)."
Exit Sub
End Try

Dim iBPID As Integer
Dim sYear, sFirstName, sLastName, sMailingAddress, sCity,
sPostalCode, sPhone, sAltPhone, sCellPhone, sFax As String
Dim sEmail, sFireProtectionArea, sBurnDescription, sApplicationDate,
sOwnerFirstName, sOwnerLastName, sPrimfolio, sBurnLocationAddress,
sApplicationSubmittedBy, sPropertyType As String
sYear = CType(fvMain.FindControl("Year"), DropDownList).SelectedValue
sFirstName = CType(fvMain.FindControl("First_Name"), TextBox).Text
sLastName = CType(fvMain.FindControl("Last_Name"), TextBox).Text
sMailingAddress = CType(fvMain.FindControl("Mailing_Address"),
TextBox).Text
sCity = CType(fvMain.FindControl("City"), TextBox).Text
sPostalCode = CType(fvMain.FindControl("Postal_Code"), TextBox).Text
sPhone = CType(fvMain.FindControl("Phone"), TextBox).Text
sAltPhone = CType(fvMain.FindControl("Alt_Phone"), TextBox).Text
sCellPhone = CType(fvMain.FindControl("Cell_Phone"), TextBox).Text
sFax = CType(fvMain.FindControl("Fax"), TextBox).Text
sEmail = CType(fvMain.FindControl("Email"), TextBox).Text
sFireProtectionArea =
CType(fvMain.FindControl("Fire_Protection_Area"), DropDownList).SelectedValue
sBurnDescription = CType(fvMain.FindControl("Burn_Description"),
TextBox).Text
sApplicationDate = Now().ToString
sOwnerFirstName = CType(fvMain.FindControl("Owner_First_Name"),
TextBox).Text
sOwnerLastName = CType(fvMain.FindControl("Owner_Last_Name"),
TextBox).Text
sPrimfolio = CType(fvMain.FindControl("Primfolio"), TextBox).Text
sBurnLocationAddress = CType(fvMain.FindControl("Burn_Address"),
TextBox).Text
sApplicationSubmittedBy =
CType(fvMain.FindControl("ApplicationSubmitedBy"), DropDownList).SelectedValue
sPropertyType = CType(fvMain.FindControl("rblPropertyType"),
RadioButtonList).SelectedValue
iBPID = DeterminBPID(oCon, sYear)
If iBPID > 0 Then
sdsMain.InsertParameters("BPID").DefaultValue = CStr(iBPID)
sdsMain.InsertParameters("FirstName").DefaultValue = sFirstName
sdsMain.InsertParameters("LastName").DefaultValue = sLastName
sdsMain.InsertParameters("MailingAddress").DefaultValue =
sMailingAddress
sdsMain.InsertParameters("City").DefaultValue = sCity
sdsMain.InsertParameters("PostalCode").DefaultValue = sPostalCode
sdsMain.InsertParameters("Phone").DefaultValue = sPhone
sdsMain.InsertParameters("AltPhone").DefaultValue = sAltPhone
sdsMain.InsertParameters("CellPhone").DefaultValue = sCellPhone
sdsMain.InsertParameters("Fax").DefaultValue = sFax
sdsMain.InsertParameters("Email").DefaultValue = sEmail
sdsMain.InsertParameters("FireProtectionArea").DefaultValue =
sFireProtectionArea
sdsMain.InsertParameters("BurnDescription").DefaultValue =
sBurnDescription
sdsMain.InsertParameters("ApplicationDate").DefaultValue =
sApplicationDate
sdsMain.InsertParameters("OwnerFirstName").DefaultValue =
sOwnerFirstName
sdsMain.InsertParameters("OwnerLastName").DefaultValue =
sOwnerLastName
sdsMain.InsertParameters("Primfolio").DefaultValue = sPrimfolio
sdsMain.InsertParameters("BurnLocationAddress").DefaultValue =
sBurnLocationAddress
sdsMain.InsertParameters("ApplicationSubmitedBy").DefaultValue =
sApplicationSubmittedBy
sdsMain.InsertParameters("PropertyType").DefaultValue =
sPropertyType
Else
'Abort
'TODO:Redirect to error page
Exit Sub
End If

Dim sToEmailAddress, sFrom, sSenderEmailAddress, sEmailSubject As
String
Try
''Email addresses
sEmailSubject = "Burning Permit Application"
sSenderEmailAddress = "(e-mail address removed)"
sFrom = "Burning Permit Internal Application"

sSQL = "SELECT Email FROM BurningInfo WHERE Fire_Prot_Area =
@FireProtectionArea"
Dim oCmd As New Data.SqlClient.SqlCommand
oCmd.Connection = oCon
oCmd.CommandText = sSQL
oCmd.Parameters.AddWithValue("@FireProtectionArea",
sFireProtectionArea)
sToEmailAddress = oCmd.ExecuteScalar.ToString
If sToEmailAddress = "" Then
sToEmailAddress = "(e-mail address removed)"
End If

''=================================================================
'' Uncomment if you want to test.

''=================================================================
sToEmailAddress = "(e-mail address removed)"

''=================================================================

oCmd = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication:Selecting Fire Department Email)."
Exit Sub
End Try

Try
Dim emailText As String
emailText = "<html><table cellpadding=2>" & vbNewLine & _
"<tr><td colspan=2>An Online Burning Permit Application has been
submitted via the RDOS intranet website.</td></tr>" & _
"<tr><td colspan=2>Please follow the link below and
approve/disapprove the application.</td></tr>" & _
"<tr><td colspan=2>---- Contact Information ----</td></tr>" & _
"<tr><td>Burning Permit ID:</td><td>" & iBPID & "</td></tr>" & _
"<tr><td>First Name:</td><td>" & sFirstName & "</td></tr>" & _
"<tr><td>Last Name:</td><td>" & sLastName & "</td></tr>" & _
"<tr><td>Owner's First Name:</td><td>" & sOwnerFirstName &
"</td></tr>" & _
"<tr><td>Owner's Last Name:</td><td>" & sOwnerLastName &
"</td></tr>" & _
"<tr><td>Mailing Address:</td><td>" & sMailingAddress &
"</td></tr>" & _
"<tr><td>City/Town:</td><td>" & sCity & "</td></tr>" & _
"<tr><td>Postal Code:</td><td>" & sPostalCode & "</td></tr>" & _
"<tr><td>Phone:</td><td>" & sPhone & "</td></tr>" & _
"<tr><td>Alternative Phone:</td><td>" & sAltPhone & "</td></tr>"
& _
"<tr><td>Cell Phone:</td><td>" & sCellPhone & "</td></tr>" & _
"<tr><td>Fax:</td><td>" & sFax & "</td></tr>" & _
"<tr><td>Email:</td><td>" & sEmail & "</td></tr>" & _
"<tr><td colspan=2>---- Burn Information ----</td></tr>" & _
"<tr><td>Address of Burn Location:</td><td>" &
sBurnLocationAddress & "</td></tr>" & _
"<tr><td>Fire Protection Area:</td><td>" & sFireProtectionArea &
"</td></tr>" & _
"<tr><td>Burn Description:</td><td>" & sBurnDescription &
"</td></tr>" & _
"<tr><td>Property Type:</td><td>" & sPropertyType & "</td></tr>"
& _
"<tr><td colspan=2>---- Follow up ----</td></tr>" & _
"<tr><td>Application Submited By:</td><td>" &
sApplicationSubmittedBy & "</td></tr>" & _
"<tr><td><a
href=http://www.rdosmaps.bc.ca/BurningPermitX/TrackPermit.aspx?BPID=" & iBPID
& ">Click Here</a></td></tr></table></html>"

Dim oFromMailAddress As New
Net.Mail.MailAddress(sSenderEmailAddress, sFrom)
Dim oToMailAddress As New Net.Mail.MailAddress(sToEmailAddress)

Dim oMessage As New Net.Mail.MailMessage(oFromMailAddress,
oToMailAddress)
oMessage.Subject = sEmailSubject
oMessage.IsBodyHtml = True
oMessage.Body = emailText
Dim client As New Net.Mail.SmtpClient("rdosmail", 25)
client.Send(oMessage)
oMessage.Dispose()
oMessage = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication_submitSending Email)."
Exit Sub
End Try

oCon.Close()
End Sub

End Class
 
Back
Top