I have several combo boxes on a single web page. I will include both the display (.aspx) code and the code behind code below shortly.
After page load, selecting an entry from the first combo box (Cycle) triggers the loading of both the second (Election) and third combo boxes (Political Race). All of this cascading works fine, until (for example) when the page does not validate due to the custom validation on the very last textbox on the page (Web Site URL).
If an error is found on this custom validation, the page is refreshed and both the second and third combo boxes (Election and Political Race) have lost their selections. Once this happens, then errors are displayed for the second and third combo boxes and for the "Web Site URL" as well and this creates a kind of "deadly embrace" that the user cannot remove themselves from.
My basic question is "Why are the Election and Political Race combo boxes losing their selection during this validation process and what can I do to prevent this loss?
Here is the .aspx code. The code behind follows.
Now the code behind...
Sorry to have to load so much code. I hope you can give me an idea of how to resolve this problem.
Thanks in advance!
Lynn
After page load, selecting an entry from the first combo box (Cycle) triggers the loading of both the second (Election) and third combo boxes (Political Race). All of this cascading works fine, until (for example) when the page does not validate due to the custom validation on the very last textbox on the page (Web Site URL).
If an error is found on this custom validation, the page is refreshed and both the second and third combo boxes (Election and Political Race) have lost their selections. Once this happens, then errors are displayed for the second and third combo boxes and for the "Web Site URL" as well and this creates a kind of "deadly embrace" that the user cannot remove themselves from.
My basic question is "Why are the Election and Political Race combo boxes losing their selection during this validation process and what can I do to prevent this loss?
Here is the .aspx code. The code behind follows.
<%@ Page Title="Campaign Finance - Create New Petition" Language="C#" MasterPageFile="~/Masters/EPSDev2.master" AutoEventWireup="true" CodeFile="NewPetition.aspx.cs" Inherits="NewPetition" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"PageHeadContent"
Runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"PageContent"
Runat
=
"Server"
>
<
div
style
=
"width: 100%;"
>
<
div
style
=
"float: left; background-color: White; padding: 10px;"
>
<
table
cellpadding
=
"20"
cellspacing
=
"0"
border
=
"0"
>
<
tr
>
<
td
width
=
"5%"
>
</
td
>
<
td
align
=
"center"
width
=
"90%"
nowrap
=
"nowrap"
>
<
table
cellpadding
=
"0"
cellspacing
=
"15"
id
=
"TABLE1"
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
>
<
h2
>
<
asp:Label
ID
=
"VoterAuthenticationLabel"
runat
=
"server"
Text
=
"Create New Petition"
></
asp:Label
>
</
h2
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
style
=
"font-weight: normal; height: 12px;"
>
<
asp:Label
ID
=
"InfoLabel"
runat
=
"server"
Text
=
"(Please enter the information requested below and then click on the SUBMIT button)"
></
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
style
=
"font-weight: normal; height: 12px;"
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"left"
style
=
"font-weight: normal; height: 12px;"
>
<
asp:Label
ID
=
"Label6"
runat
=
"server"
Font-Bold
=
"true"
Text
=
"CANDIDATE INFORMATION:"
></
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"CycleLabel"
runat
=
"server"
Text
=
"Cycle:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadComboBox
ID
=
"ElectionCycleList"
runat
=
"server"
TabIndex
=
"1"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
OnClientSelectedIndexChanging
=
"LoadPoliticalRaceList"
>
</
telerik:RadComboBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"ElectionCycleListReqd"
ControlToValidate
=
"ElectionCycleList"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must select an Election Cycle from the list"
ForeColor="Red">
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator5"
runat
=
"server"
ControlToValidate
=
"ElectionCycleList"
ClientValidationFunction
=
"validateCombo5"
ErrorMessage="<br>You must select an Election Cycle from the list"
ValidationGroup="DEForm" Display="Dynamic" ForeColor="Red"
>
</
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label14"
runat
=
"server"
Text
=
"Election:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadComboBox
ID
=
"ElectionList"
runat
=
"server"
TabIndex
=
"1"
OnClientItemsRequested
=
"SearchItemsLoaded"
OnItemsRequested
=
"ElectionList_ItemsRequested"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
EnableViewState
=
"true"
ViewStateMode
=
"Enabled"
>
</
telerik:RadComboBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"ElectionListReqd"
ControlToValidate
=
"ElectionList"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must select an Election from the list."
ForeColor="Red">
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator4"
runat
=
"server"
ControlToValidate
=
"ElectionList"
ClientValidationFunction
=
"validateCombo4"
ErrorMessage="<br>You must select an Election from the list"
ValidationGroup="DEForm" Display="Dynamic" ForeColor="Red"
>
</
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"Political Race:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadComboBox
ID
=
"PoliticalRaceList"
Width
=
"250px"
runat
=
"server"
TabIndex
=
"2"
OnClientItemsRequested
=
"SearchItemsLoaded"
OnItemsRequested
=
"PoliticalRaceList_ItemsRequested"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
>
</
telerik:RadComboBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"PoliticalRaceListReqd"
ControlToValidate
=
"PoliticalRaceList"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must select a Political Race from the list"
ForeColor="Red">
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator3"
runat
=
"server"
ControlToValidate
=
"PoliticalRaceList"
ClientValidationFunction
=
"validateCombo3"
ErrorMessage="<br>You must select a Political Race from the list"
ValidationGroup="DEForm" Display="Dynamic" ForeColor="Red"
>
</
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label12"
runat
=
"server"
Text
=
"Political Party:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadComboBox
ID
=
"PoliticalPartyList"
runat
=
"server"
TabIndex
=
"3"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
>
</
telerik:RadComboBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
ControlToValidate
=
"PoliticalPartyList"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must select a Political Party from the list"
ForeColor="Red">
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator2"
runat
=
"server"
ControlToValidate
=
"PoliticalPartyList"
ClientValidationFunction
=
"validateCombo2"
ErrorMessage="<br>You must select a Political Party from the list"
ValidationGroup="DEForm" Display="Dynamic" ForeColor="Red"
>
</
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label2"
runat
=
"server"
Text
=
"Name:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"CandidateName"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"4"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"CandidateNameReqd"
ControlToValidate
=
"CandidateName"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Candidate's Name"
ForeColor="Red"></
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label3"
runat
=
"server"
Text
=
"Address:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"CandidateAddress1"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"5"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
> <
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"CandidateAddress1Reqd"
ControlToValidate
=
"CandidateAddress1"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Candidate's Address"
ForeColor="Red"></
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label13"
runat
=
"server"
Text
=
"Address 2:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"CandidateAddress2"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"5"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
br
/>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label4"
runat
=
"server"
Text
=
"City, State, Zip Code:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"CandidateCity"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"6"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
telerik:RadTextBox
ID
=
"CandidateState"
runat
=
"server"
MaxLength
=
"2"
Width
=
"30px"
TabIndex
=
"7"
Text
=
"AZ"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
telerik:RadTextBox
ID
=
"CandidateZipCode"
runat
=
"server"
TabIndex
=
"8"
MaxLength
=
"10"
Width
=
"75px"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"CandidateCityReqd"
ControlToValidate
=
"CandidateCity"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Candidate's City"
ForeColor="Red"></
asp:RequiredFieldValidator
>
<
asp:RequiredFieldValidator
ID
=
"CandidateStateReqd"
ControlToValidate
=
"CandidateState"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Candidate's State"
ForeColor="Red"></
asp:RequiredFieldValidator
>
<
asp:RequiredFieldValidator
ID
=
"CandidateZipCodeReqd"
ControlToValidate
=
"CandidateZipCode"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Candidate's Zip Code"
ForeColor="Red"></
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label5"
runat
=
"server"
Text
=
"County:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadComboBox
ID
=
"CandidateCountyList"
runat
=
"server"
TabIndex
=
"9"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
>
</
telerik:RadComboBox
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"CandidateCountyListReqd"
ControlToValidate
=
"CandidateCountyList"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must select the Candidate's County from the list"
ForeColor="Red">
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator1"
runat
=
"server"
ControlToValidate
=
"CandidateCountyList"
ClientValidationFunction
=
"validateCombo1"
ErrorMessage="<br>You must select the Candidate's County"
ValidationGroup="DEForm" Display="Dynamic" ForeColor="Red"
>
</
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
style
=
"font-weight: normal; height: 12px;"
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"left"
style
=
"font-weight: normal; height: 12px;"
>
<
asp:Label
ID
=
"Label7"
runat
=
"server"
Font-Bold
=
"true"
Text
=
"CONTACT INFORMATION:"
></
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label8"
runat
=
"server"
Text
=
"Name:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"ContactName"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"10"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
> <
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
<
asp:RequiredFieldValidator
ID
=
"ContactNameReqd"
ControlToValidate
=
"ContactName"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>You must enter the Contact's Name"
ForeColor="Red"></
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label9"
runat
=
"server"
Text
=
"Telephone:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"ContactPhone"
runat
=
"server"
MaxLength
=
"25"
Width
=
"100px"
TabIndex
=
"11"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
><
br
/>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label10"
runat
=
"server"
Text
=
"Email Address:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"ContactEmailAddress"
runat
=
"server"
MaxLength
=
"256"
Width
=
"300px"
TabIndex
=
"12"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
><
br
/>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
>
<
asp:Label
ID
=
"Label11"
runat
=
"server"
Text
=
"Web Site URL:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
>
<
telerik:RadTextBox
ID
=
"ContactWebSiteURL"
runat
=
"server"
MaxLength
=
"50"
Width
=
"200px"
TabIndex
=
"13"
EnableEmbeddedSkins
=
"true"
Skin
=
"Default"
></
telerik:RadTextBox
>
<
asp:CustomValidator
ID
=
"ContactWebSiteURLCustom"
ControlToValidate
=
"ContactWebSiteURL"
ValidationGroup
=
"DEForm"
Display
=
"Dynamic"
runat
=
"server"
ErrorMessage="<br>If provided, the web site URL must be present on the Internet."
ForeColor="Red" OnServerValidate="ValidateURL" ></
asp:CustomValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
style
=
"font-weight: normal; height: 12px;"
>
<
asp:Button
ID
=
"CreateButton"
runat
=
"server"
Text
=
"Create Petition"
TabIndex
=
"15"
ValidationGroup
=
"DEForm"
onclick
=
"CreateButton_Click"
/>
<
asp:Button
ID
=
"CancelButton"
runat
=
"server"
Text
=
"Cancel Petition"
TabIndex
=
"16"
onclick
=
"CancelButton_Click"
/>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
align
=
"center"
style
=
"font-weight: normal; height: 12px;"
>
<
img
alt
=
"Required field"
src
=
"<%=ResolveUrl("
images/required2.gif")%>" />
-
<
asp:Label
ID
=
"IndicatesRequiredLabel"
runat
=
"server"
Text
=
"Indicates a required field"
></
asp:Label
>
<
br
/>
<
asp:Label
ID
=
"StatusLabel"
ForeColor
=
"Red"
runat
=
"server"
/>
<
asp:ValidationSummary
ID
=
"ValidationSummary1"
ValidationGroup
=
"DEForm"
DisplayMode
=
"List"
ForeColor
=
"Red"
ShowSummary
=
"False"
runat
=
"server"
/>
</
td
>
</
tr
>
</
table
>
</
td
>
<
td
width
=
"5%"
>
</
td
>
</
tr
>
</
table
>
</
div
>
<
div
class
=
"clear"
>
</
div
>
</
div
>
<
script
type
=
"text/javascript"
>
function LoadPoliticalRaceList(combo, eventArqs) {
var searchcycleCombo = $find("<%=ElectionCycleList.ClientID%>");
var searchraceCombo = $find("<%=PoliticalRaceList.ClientID%>");
var searchelectionCombo = $find("<%=ElectionList.ClientID%>");
var item = eventArqs.get_item();
searchraceCombo.set_text("Loading...");
// if a cycle is selected
if (item.get_index() > 0) {
// this will fire the ItemsRequested event of the
// property type combobox passing the transaction type as a parameter
searchraceCombo.requestItems(item.get_value(), false);
}
else {
// the -Select a cycle- item was chosen
searchraceCombo.set_text(" ");
searchraceCombo.clearItems();
}
var item = eventArqs.get_item();
searchelectionCombo.set_text("Loading...");
// if a cycle is selected
if (item.get_index() > 0) {
// this will fire the ItemsRequested event of the
// property type combobox passing the transaction type as a parameter
searchelectionCombo.requestItems(item.get_value(), false);
}
else {
// the -Select a cycle- item was chosen
searchelectionCombo.set_text(" ");
searchelectionCombo.clearItems();
}
}
function SearchItemsLoaded(combo, eventArqs) {
if (combo.get_items().get_count() > 0) {
// pre-select the first item
combo.set_text(combo.get_items().getItem(0).get_text());
combo.get_items().getItem(0).highlight();
}
}
function validateCombo1(source, args) {
args.IsValid = false;
var combo = $find("<%= CandidateCountyList.ClientID %>");
var text = combo.get_text();
if (text.length <
1
) {
args.IsValid
=
false
;
}
else {
var
node
=
combo
.findItemByText(text);
if (node) {
var
value
=
node
.get_value();
if (value.length > 0) {
args.IsValid = true;
}
}
else {
args.IsValid = false;
}
}
}
function validateCombo2(source, args) {
args.IsValid = false;
var combo = $find("<%= PoliticalPartyList.ClientID %>");
var text = combo.get_text();
if (text.length <
1
) {
args.IsValid
=
false
;
}
else {
var
node
=
combo
.findItemByText(text);
if (node) {
var
value
=
node
.get_value();
if (value.length > 0) {
args.IsValid = true;
}
}
else {
args.IsValid = false;
}
}
}
function validateCombo3(source, args) {
args.IsValid = false;
var combo = $find("<%= PoliticalRaceList.ClientID %>");
var text = combo.get_text();
if (text.length <
1
) {
args.IsValid
=
false
;
}
else {
var
node
=
combo
.findItemByText(text);
if (node) {
var
value
=
node
.get_value();
if (value.length > 0) {
args.IsValid = true;
}
}
else {
args.IsValid = false;
}
}
}
function validateCombo4(source, args) {
args.IsValid = false;
var combo = $find("<%= ElectionList.ClientID %>");
var text = combo.get_text();
if (text.length <
1
) {
args.IsValid
=
false
;
}
else {
var
node
=
combo
.findItemByText(text);
if (node) {
var
value
=
node
.get_value();
if (value.length > 0) {
args.IsValid = true;
}
}
else {
args.IsValid = false;
}
}
}
function validateCombo5(source, args) {
args.IsValid = false;
var combo = $find("<%= ElectionCycleList.ClientID %>");
var text = combo.get_text();
if (text.length <
1
) {
args.IsValid
=
false
;
}
else {
var
node
=
combo
.findItemByText(text);
if (node) {
var
value
=
node
.get_value();
if (value.length > 0) {
args.IsValid = true;
}
}
else {
args.IsValid = false;
}
}
}
</
script
>
</
asp:Content
>
Now the code behind...
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.Data.SqlClient;
using
System.Configuration;
using
System.Data;
using
System.Text;
using
System.Net;
using
System.IO;
public
partial
class
NewPetition : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
// The purpose of this page is to initiate the creation of a new petition.
// We need to check for the presence of the query string member '19' and if its value is 'edt'.
// If yes to both of these questions, then the user has already entered the data for a new petition but
// clicked the edit button on the next confirmation page.
// If the answer to either of these is no, then we will give the user an empty page to enter data into
// except for the three (3) combo boxes --the Election Cycle, Political Party and the County combo boxes.
// The Political Race combo box will be dynamically loaded after the user selects an Election Cycle.
if
(!Page.IsPostBack)
{
// If this is the new petition data coming back for edit from the confirmation page,
// then load the screen controls up with the data
if
(Request.QueryString[
"19"
] ==
"edt"
)
{
this
.CandidateName.Text = Request.QueryString[
"4"
];
this
.CandidateAddress1.Text = Request.QueryString[
"5"
];
this
.CandidateAddress2.Text = Request.QueryString[
"6"
];
this
.CandidateCity.Text = Request.QueryString[
"7"
];
this
.CandidateState.Text = Request.QueryString[
"8"
];
this
.CandidateZipCode.Text = Request.QueryString[
"9"
];
this
.ContactName.Text = Request.QueryString[
"11"
];
this
.ContactPhone.Text = Request.QueryString[
"12"
];
this
.ContactEmailAddress.Text = Request.QueryString[
"13"
];
this
.ContactWebSiteURL.Text = Request.QueryString[
"14"
];
LoadElectionCycleList2(
this
.ElectionCycleList, Request.QueryString[
"1"
]);
LoadPoliticalRaceList2(
this
.PoliticalRaceList, Request.QueryString[
"2"
]);
LoadPoliticalPartyList2(
this
.PoliticalPartyList, Request.QueryString[
"3"
]);
LoadCountyList2(
this
.CandidateCountyList, Request.QueryString[
"10"
]);
LoadElectionList2(
this
.ElectionList, Request.QueryString[
"20"
]);
}
else
// This is a new page request so only load the combo boxes,
// there is nothing else to do
{
this
.CandidateName.Text = Convert.ToString(Session[
"CandidateFullName"
]);
LoadElectionCycleList(
this
.ElectionCycleList);
LoadPoliticalPartyList(
this
.PoliticalPartyList);
LoadCountyList(
this
.CandidateCountyList);
}
}
else
{
string
sCB1 = Convert.ToString(
this
.ElectionList.SelectedValue);
string
sCB2 = Convert.ToString(
this
.PoliticalRaceList.SelectedValue);
string
a =
"abc"
;
}
}
protected
void
ElectionList_ItemsRequested(
object
o, RadComboBoxItemsRequestedEventArgs e)
{
// The user-selected Election Cycle value is passed to us so can correctly populate this list
LoadElectionList(
this
.ElectionList, e.Text);
}
private
void
LoadElectionList2(RadComboBox combobox,
string
cbval)
{
LoadElectionList(
this
.ElectionList, Request.QueryString[
"1"
]);
this
.ElectionList.SelectedValue = cbval;
}
private
void
LoadElectionCycleList2(RadComboBox combobox,
string
cbval)
{
LoadElectionCycleList(
this
.ElectionCycleList);
this
.ElectionCycleList.SelectedValue = cbval;
}
private
void
LoadPoliticalRaceList2(RadComboBox combobox,
string
cbval)
{
LoadPoliticalRaceList(
this
.PoliticalRaceList, Request.QueryString[
"1"
]);
//LoadPoliticalRaceList(this.PoliticalRaceList, Request.QueryString["15"]);
this
.PoliticalRaceList.SelectedValue = cbval;
}
private
void
LoadPoliticalPartyList2(RadComboBox combobox,
string
cbval)
{
LoadPoliticalPartyList(
this
.PoliticalPartyList);
this
.PoliticalPartyList.SelectedValue = cbval;
}
private
void
LoadCountyList2(RadComboBox combobox,
string
cbval)
{
LoadCountyList(
this
.CandidateCountyList);
this
.CandidateCountyList.SelectedValue = cbval;
}
private
void
LoadElectionList(RadComboBox combobox,
string
electioncycleno)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ElectronicPetitionSystemConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT TOP (100) PERCENT ElectionName, ElectionId, CycleId, ElectionDate FROM dbo.Elections WHERE (CycleId = "
+ electioncycleno +
") ORDER BY ElectionDate"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combobox.DataTextField =
"ElectionName"
;
combobox.DataValueField =
"ElectionId"
;
combobox.DataSource = dt;
combobox.DataBind();
// Insert the first item.
combobox.Items.Insert(0,
new
RadComboBoxItem(
"- Select an election -"
));
}
protected
void
ElectList_ItemsRequested(
object
o, RadComboBoxItemsRequestedEventArgs e)
{
// The user-selected Election Cycle value is passed to us so can correctly populate this list
LoadElectionList(
this
.ElectionList, e.Text);
}
private
void
LoadElectionCycleList(RadComboBox combobox)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ElectronicPetitionSystemConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT CycleId, CycleName FROM Cycles WHERE EndDate > GETDATE() ORDER By CycleName"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combobox.DataTextField =
"CycleName"
;
combobox.DataValueField =
"CycleId"
;
combobox.DataSource = dt;
combobox.DataBind();
// Insert the first item.
combobox.Items.Insert(0,
new
RadComboBoxItem(
"- Select a cycle -"
));
}
protected
void
PoliticalRaceList_ItemsRequested(
object
o, RadComboBoxItemsRequestedEventArgs e)
{
// The user-selected Election Cycle value is passed to us so can correctly populate this list
LoadPoliticalRaceList(
this
.PoliticalRaceList, e.Text);
}
private
void
LoadPoliticalRaceList(RadComboBox combobox,
string
electioncycleno)
{
if
(electioncycleno.Length > 0)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ElectronicPetitionSystemConnectionString"
].ConnectionString);
string
sqlcode =
"SELECT Cycles.CycleId, Cycles.CycleName, Cycles.BeginDate, Races.RaceId, Offices.OfficeId, Offices.OfficeDescription FROM Cycles INNER JOIN Races ON Cycles.CycleId = Races.CycleId INNER JOIN Offices ON Races.OfficeId = Offices.OfficeId WHERE Cycles.CycleId = "
+ electioncycleno +
" ORDER BY OfficeDescription"
;
SqlDataAdapter adapter =
new
SqlDataAdapter(sqlcode, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combobox.DataTextField =
"OfficeDescription"
;
combobox.DataValueField =
"RaceId"
;
combobox.DataSource = dt;
combobox.DataBind();
// Insert the first item.
combobox.Items.Insert(0,
new
RadComboBoxItem(
"- Select a race"
));
}
}
private
void
LoadPoliticalPartyList(RadComboBox combobox)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ElectronicPetitionSystemConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT PartyId, PartyName, DisplayOrder FROM Parties ORDER By DisplayOrder"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combobox.DataTextField =
"PartyName"
;
combobox.DataValueField =
"PartyId"
;
combobox.DataSource = dt;
combobox.DataBind();
// Insert the first item.
combobox.Items.Insert(0,
new
RadComboBoxItem(
"- Select a party -"
));
}
private
void
LoadCountyList(RadComboBox combobox)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ElectronicPetitionSystemConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT CountyId, CountyName FROM Counties ORDER By CountyName"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combobox.DataTextField =
"CountyName"
;
combobox.DataValueField =
"CountyId"
;
combobox.DataSource = dt;
combobox.DataBind();
// Insert the first item.
combobox.Items.Insert(0,
new
RadComboBoxItem(
"- Select a county -"
));
}
protected
void
CreateButton_Click(
object
sender, EventArgs e)
{
// Create the new petition if the input validates
if
(Page.IsValid)
{
// If the data entered is valid, then send the user (and the data) to the Confirmation page to make
// certain that they actually do want to create the new petition before doing it, otherwise .NET will
// send them back to correct the data
string
sQueryString =
""
;
sQueryString +=
"1="
+
this
.ElectionCycleList.SelectedValue;
sQueryString +=
"&2="
+
this
.PoliticalRaceList.SelectedValue;
sQueryString +=
"&3="
+
this
.PoliticalPartyList.SelectedValue;
sQueryString +=
"&4="
+
this
.CandidateName.Text;
sQueryString +=
"&5="
+
this
.CandidateAddress1.Text;
sQueryString +=
"&6="
+
this
.CandidateAddress2.Text;
sQueryString +=
"&7="
+
this
.CandidateCity.Text;
sQueryString +=
"&8="
+
this
.CandidateState.Text;
sQueryString +=
"&9="
+
this
.CandidateZipCode.Text;
sQueryString +=
"&10="
+
this
.CandidateCountyList.SelectedValue;
sQueryString +=
"&11="
+
this
.ContactName.Text;
sQueryString +=
"&12="
+
this
.ContactPhone.Text;
sQueryString +=
"&13="
+
this
.ContactEmailAddress.Text;
sQueryString +=
"&14="
+
this
.ContactWebSiteURL.Text;
sQueryString +=
"&15="
+
this
.ElectionCycleList.Text;
sQueryString +=
"&16="
+
this
.PoliticalRaceList.Text;
sQueryString +=
"&17="
+
this
.PoliticalPartyList.Text;
sQueryString +=
"&18="
+
this
.CandidateCountyList.Text;
sQueryString +=
"&20="
+
this
.ElectionList.SelectedValue;
sQueryString +=
"&21="
+
this
.ElectionList.Text;
Response.Redirect(
"NewPetitionConf.aspx?"
+ sQueryString);
}
}
protected
void
CancelButton_Click(
object
sender, EventArgs e)
{
// If the user cancels the new petition, then we need to back to MyeDocs.aspx
Response.Redirect(
"MyEDocs.aspx"
);
}
protected
void
ValidateURL(
object
source, ServerValidateEventArgs args)
{
args.IsValid =
true
;
WebRequest webRequest =
null
;
WebResponse webResponse =
null
;
try
{
webRequest = WebRequest.Create(
this
.ContactWebSiteURL.Text);
webResponse = webRequest.GetResponse();
}
catch
(UriFormatException ex)
{
ContactWebSiteURLCustom.ErrorMessage = ex.Message;
args.IsValid =
false
;
}
catch
(WebException ex)
{
ContactWebSiteURLCustom.ErrorMessage = ex.Message;
args.IsValid =
false
;
if
(ex.Response !=
null
&& ex.Response.Headers !=
null
)
{
ContactWebSiteURLCustom.ErrorMessage = ex.Message;
//+ " - Web Exception - " + ex.Response.Headers.ToString();
args.IsValid =
false
;
}
ContactWebSiteURLCustom.ErrorMessage = ex.Message;
//+ " - \nStack Trace Error - " + ex.ToString();
args.IsValid =
false
;
}
catch
(Exception ex)
{
ContactWebSiteURLCustom.ErrorMessage = ex.Message;
//+ " - \nStack Trace Error - " + ex.ToString();
args.IsValid =
false
;
}
finally
{
if
(webResponse !=
null
)
{
webResponse.Close();
}
}
Boolean bFlag = args.IsValid;
}
}
Sorry to have to load so much code. I hope you can give me an idea of how to resolve this problem.
Thanks in advance!
Lynn