I'm having issues trying to get radio button list selected index changes to fire, and although I have no issues with postbacks on any other asp control, radio button lists are giving me trouble. I'll include my asp code and c# codebehind in the event one of you may be able to discern what's wrong.
I have 8 radio button lists, all within their own update panels that are set to always update, and each radio button list has autopostback set to true.
I have code behind logic changing two asp:labels, one changing the average scores based on the radiobuttonlist selections, and one assigning a risk level depending on the value of the average score.
<table class="td-table-bordered" style="width: 90%">
<tr>
<th>
<asp:Label ID="CategoryLabel" runat="server" Text="Category"></asp:Label>
</th>
<th>
<asp:Label ID="OccurrenceProbabilityLabel" runat="server" Text="Probability of Occurrence"></asp:Label>
</th>
<th>
<asp:Label ID="ProbabilityRatingLabel" runat="server" Text="Rating"></asp:Label><br />
<asp:Label ID="ProbabilityRatingLabel2" runat="server" Text="(L/M/H)"></asp:Label>
</th>
<th>
<asp:Label ID="OccurrenceImpactLabel" runat="server" Text="Impact of Occurrence"></asp:Label>
</th>
<th>
<asp:Label ID="ImpactRatingLabel" runat="server" Text="Rating"></asp:Label><br />
<asp:Label ID="ImpactRatingLabel2" runat="server" Text="(L/M/H)"></asp:Label>
</th>
</tr>
<tr>
<td>
<asp:Label ID="BaseDesktopLabel" runat="server" Text="Base Desktop"></asp:Label>
</td>
<td>
<asp:Label ID="BaseDesktopProbabilityLabel" runat="server" Text="Based on workspace/RBB assessment, what is the probability that this change could impact function, performance or availability of a base component?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="DesktopProbabilityPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="DesktopProbabilityButtonList" runat="server" OnSelectedIndexChanged="DesktopProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:Label ID="BaseDesktopImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the workstation?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="DesktopImpactPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="DesktopImpactButtonList" runat="server" OnSelectedIndexChanged="DesktopImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="ProductivityLayerLabel" runat="server" Text="Productivity Layer"></asp:Label>
</td>
<td>
<asp:Label ID="ProductivityLayerProbabilityLabel" runat="server" Text="Based on workspace/RBB engineering assessment, what is the probability that this change could impact function, performance or availability of a productivity application?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="ProductivityProbabilityPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="ProductivityProbabilityButtonList" runat="server" OnSelectedIndexChanged="ProductivityProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:Label ID="ProductivityLayerImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the productivity application?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="ProductivityImpactPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="ProductivityImpactButtonList" runat="server" OnSelectedIndexChanged="ProductivityImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="BusinessApplicationsLabel" runat="server" Text="Business Applications"></asp:Label>
</td>
<td>
<asp:Label ID="BusinessApplicationsProbabilityLabel" runat="server" Text="Based on workspace engineering assessment, what is the probability that this change could impact function, performance or availability of a business application?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="BusinessProbabilityPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="BusinessProbabilityButtonList" runat="server" OnSelectedIndexChanged="BusinessProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:Label ID="BusinessApplicationsImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the business application?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="BusinessImpactPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="BusinessImpactButtonList" runat="server" OnSelectedIndexChanged="BusinessImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="DatacenterLabel" runat="server" Text="Datacenter/Infrastructure"></asp:Label>
</td>
<td>
<asp:Label ID="DatacenterProbabilityLabel" runat="server" Text="What is the probability that this change could impact function, performance or availability of networks, infrastructure or web services used by the branch??"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="DatacenterProbabilityPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="DatacenterProbabilityButtonList" runat="server" OnSelectedIndexChanged="DatacenterProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:Label ID="DataCenterImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the datacenter or infrastructure?"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="DataCenterImpactPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButtonList ID="DatacenterImpactButtonList" runat="server" OnSelectedIndexChanged="DatacenterImpactList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td> </td>
<td style="text-align: right">
<asp:Label ID="OverAllRatingLabel" runat="server" Font-Bold="True" Text="Change Risks Overall Average Rating: "></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRating" runat="server" Font-Bold="True"></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRiskLabel" runat="server" Font-Bold="True" Text="Overall Risk: "></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRisk" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
</table>
And now my c#
double averageRating, desktopProbabilityRating, desktopImpactRating, productivityProbabilityRating, productivityImpactRating, businessProbabilityRating, businessImpactRating, datacenterProbabilityRating, datacenterImpactRating = 0;
protected void DesktopProbabilityButtonList_SelectedIndexChanged(object sender, EventArgs e) {
desktopProbabilityRating = Convert.ToDouble(DesktopProbabilityButtonList.SelectedValue);
calculateAverage();
}
protected void DesktopImpactButtonList_SelectedIndexChanged(object sender, EventArgs e) {
desktopImpactRating = Convert.ToDouble(DesktopImpactButtonList.SelectedValue);
calculateAverage();
}
protected void ProductivityProbabilityButtonList_SelectedIndexChanged(object sender, EventArgs e) {
productivityProbabilityRating = Convert.ToDouble(ProductivityProbabilityButtonList.SelectedValue);
calculateAverage();
}
protected void ProductivityImpactButtonList_SelectedIndexChanged(object sender, EventArgs e) {
productivityImpactRating = Convert.ToDouble(ProductivityImpactButtonList.SelectedValue);
calculateAverage();
}
protected void BusinessProbabilityButtonList_SelectedIndexChanged(object sender, EventArgs e) {
businessProbabilityRating = Convert.ToDouble(BusinessProbabilityButtonList.SelectedValue);
calculateAverage();
}
protected void BusinessImpactButtonList_SelectedIndexChanged(object sender, EventArgs e) {
businessImpactRating = Convert.ToDouble(BusinessImpactButtonList.SelectedValue);
calculateAverage();
}
protected void DatacenterProbabilityButtonList_SelectedIndexChanged(object sender, EventArgs e) {
datacenterProbabilityRating = Convert.ToDouble(DatacenterProbabilityButtonList.SelectedValue);
calculateAverage();
}
protected void DatacenterImpactList_SelectedIndexChanged(object sender, EventArgs e) {
datacenterImpactRating = Convert.ToDouble(DatacenterImpactButtonList.SelectedValue);
calculateAverage();
}
protected void calculateAverage() {
averageRating = (desktopProbabilityRating + desktopImpactRating + productivityProbabilityRating + productivityImpactRating + businessProbabilityRating + businessImpactRating + datacenterProbabilityRating + datacenterImpactRating) / 8;
OverallRating.Text = averageRating.ToString();
if(averageRating <= 1) {
OverallRisk.Text = "Low";
}
else if(averageRating > 1 && averageRating < 3) {
OverallRisk.Text = "Med";
}
else if(averageRating >=3 || desktopProbabilityRating == 3 || desktopImpactRating == 3 || productivityProbabilityRating == 3 || productivityImpactRating == 3 || businessProbabilityRating == 3 || businessImpactRating == 3 || datacenterProbabilityRating == 3 || datacenterImpactRating == 3) {
OverallRisk.Text = "High";
}
}
This SHOULD be posting back, I absolutely can't determine why every other control on my form posts back just fine and not these. Would someone be able to help determine why? No other question on stack overflow concerning this applied to my problem.
Thanks so much in advance.
Your labels are outside the update panels, that is why it is not working. All the radio buttons postback without any issue.
I would suggest you to wrap all the controls inside one update panel.
Please read further here https://forums.asp.net/t/1120428.aspx?Update+Label+outside+update+panel
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<table class="td-table-bordered" style="width: 90%">
<tr>
<th>
<asp:Label ID="CategoryLabel" runat="server" Text="Category"></asp:Label>
</th>
<th>
<asp:Label ID="OccurrenceProbabilityLabel" runat="server" Text="Probability of Occurrence"></asp:Label>
</th>
<th>
<asp:Label ID="ProbabilityRatingLabel" runat="server" Text="Rating"></asp:Label><br />
<asp:Label ID="ProbabilityRatingLabel2" runat="server" Text="(L/M/H)"></asp:Label>
</th>
<th>
<asp:Label ID="OccurrenceImpactLabel" runat="server" Text="Impact of Occurrence"></asp:Label>
</th>
<th>
<asp:Label ID="ImpactRatingLabel" runat="server" Text="Rating"></asp:Label><br />
<asp:Label ID="ImpactRatingLabel2" runat="server" Text="(L/M/H)"></asp:Label>
</th>
</tr>
<tr>
<td>
<asp:Label ID="BaseDesktopLabel" runat="server" Text="Base Desktop"></asp:Label>
</td>
<td>
<asp:Label ID="BaseDesktopProbabilityLabel" runat="server" Text="Based on workspace/RBB assessment, what is the probability that this change could impact function, performance or availability of a base component?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="DesktopProbabilityButtonList" runat="server" OnSelectedIndexChanged="DesktopProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Label ID="BaseDesktopImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the workstation?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="DesktopImpactButtonList" runat="server" OnSelectedIndexChanged="DesktopImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="ProductivityLayerLabel" runat="server" Text="Productivity Layer"></asp:Label>
</td>
<td>
<asp:Label ID="ProductivityLayerProbabilityLabel" runat="server" Text="Based on workspace/RBB engineering assessment, what is the probability that this change could impact function, performance or availability of a productivity application?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="ProductivityProbabilityButtonList" runat="server" OnSelectedIndexChanged="ProductivityProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Label ID="ProductivityLayerImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the productivity application?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="ProductivityImpactButtonList" runat="server" OnSelectedIndexChanged="ProductivityImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="BusinessApplicationsLabel" runat="server" Text="Business Applications"></asp:Label>
</td>
<td>
<asp:Label ID="BusinessApplicationsProbabilityLabel" runat="server" Text="Based on workspace engineering assessment, what is the probability that this change could impact function, performance or availability of a business application?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="BusinessProbabilityButtonList" runat="server" OnSelectedIndexChanged="BusinessProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Label ID="BusinessApplicationsImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the business application?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="BusinessImpactButtonList" runat="server" OnSelectedIndexChanged="BusinessImpactButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="DatacenterLabel" runat="server" Text="Datacenter/Infrastructure"></asp:Label>
</td>
<td>
<asp:Label ID="DatacenterProbabilityLabel" runat="server" Text="What is the probability that this change could impact function, performance or availability of networks, infrastructure or web services used by the branch??"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="DatacenterProbabilityButtonList" runat="server" OnSelectedIndexChanged="DatacenterProbabilityButtonList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Label ID="DataCenterImpactLabel" runat="server" Text="If a problem did occur, what could be the extent of the impact to the operation of the datacenter or infrastructure?"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="DatacenterImpactButtonList" runat="server" OnSelectedIndexChanged="DatacenterImpactList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="High" Value="3"></asp:ListItem>
<asp:ListItem Text="Med" Value="2"></asp:ListItem>
<asp:ListItem Text="Low" Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td> </td>
<td style="text-align: right">
<asp:Label ID="OverAllRatingLabel" runat="server" Font-Bold="True" Text="Change Risks Overall Average Rating: "></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRating" runat="server" Font-Bold="True"></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRiskLabel" runat="server" Font-Bold="True" Text="Overall Risk: "></asp:Label>
</td>
<td style="text-align: right">
<asp:Label ID="OverallRisk" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Related
I have a series of Dropdown boxes that contain an option for Pass or Fail. What I want to happen is if any of the 6 dropdown boxes in the panel contain a Fail selection, Button 1 appears. If there are no Fail selections made, then Button 2 appears.
Here is what I have, this doesn't seem to get all the selectedvalues of the dropdowns, only the first selection. I call the same CheckDDL() method after each DropDown_SelectedIndexChanged event. Any help is greatly appreciated!
public void CheckDDL()
{
var myDropDownLists = TestResults.Controls
.OfType<DropDownList>()
.Where(ddl => ddl.Enabled = true);
foreach (DropDownList ddl in myDropDownLists)
{
DataTable dt = new DataTable();
dt.Columns.Add("result");
string result = ddl.SelectedValue;
DataRow dr = dt.NewRow();
dr["result"] = result;
string fail = "0";
bool containsfail = dt.AsEnumerable().Any(row => fail == row.Field<String>("result"));
if (containsfail == true)
{
btnAllPass.Visible = false;
btnAddredo.Visible = true;
}
else
{
btnAllPass.Visible = true;
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
CheckDDL();
}
ASPX page code:
<asp:Panel ID="TestResults" runat="server" Width="1040px" BorderStyle="Double" BorderWidth="2px" Height="280px">
<br />
<table id="HBredotable" style="width: 625px">
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label2" runat="server" Text="Serial One:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox1" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--" Value="2"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label3" runat="server" Text="Serial Two:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox2" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label4" runat="server" Text="Serial Three:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox3" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label5" runat="server" Text="Serial Four:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox4" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList4" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label6" runat="server" Text="Serial Five:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox5" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList5" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList5_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 189px" align="center">
<asp:Label ID="Label7" runat="server" Text="Serial Six:"></asp:Label>
</td>
<td style="width: 248px">
<asp:TextBox ID="TextBox6" runat="server" Width="230px" Height="22px" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList6" runat="server" Height="22px" Width="165px" OnSelectedIndexChanged="DropDownList6_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Pass" Value="1"></asp:ListItem>
<asp:ListItem Text="Fail" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<asp:Label ID="lblREDOerror" runat="server" Text="" ForeColor="red"></asp:Label><br />
<asp:Button ID="btnAllPass" runat="server" Text="All Tests Pass / Unit Complete" Width="210px" OnClick="btnAllPass_Click"/>
<asp:Button ID="btnAddredo" runat="server" Text="Enter Hashboards for REDO" Width="210px" OnClick="btnAddredo_Click" />
<asp:Button ID="btnconfirmredo" runat="server" Text="Yes, Continue" Width="210px" OnClick="btnconfirmredo_Click" />
<asp:Button ID="btnreturn" runat="server" Text="No, Go Back" Width="210px" OnClick="btnreturn_Click" />
<br />
</asp:Panel>
So first off you are creating a new DataTable on each loop which means your code bool containsfail = dt.AsEnumerable().Any(row => fail == row.Field<String>("result")); is only checking the most recent droplist!
But I suggest you try this
var myDropDownLists = TestResults.Controls
.OfType<DropDownList>()
.Where(ddl => ddl.Enabled = true);
var anyFail = myDropDownLists.Any(dd => dd.SelectedValue == "0");
btnAllPass.Visible = !anyFail;
btnAddredo.Visible = anyFail;
you can fine tune the buttons to your liking.
Use count variable. If one of the dropdownlist contains fail then increment count to 1 and then check for count.
public void CheckDDL()
{
var myDropDownLists = TestResults.Controls
.OfType<DropDownList>()
.Where(ddl => ddl.Enabled = true);
int count=0;
foreach (DropDownList ddl in myDropDownLists)
{
string result = ddl.SelectedValue;
if(result=="fail")
{
count++;
break;
}
else
{
continue;
}
}
if (count > 0)
{
btnAllPass.Visible = false;
btnAddredo.Visible = true;
}
else
{
btnAllPass.Visible = true;
}
}
I have a RequiredFieldValidator for dropdownlist. Both are inside UpdatePanel. It is not validating user selection from dropdownlist when submit button is clicked. Please guide what am I missing.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="divFilter">
<asp:UpdatePanel ID="uplMain" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
<table>
<tr>
<td valign="top">
<table>
<tr>
<td>
<asp:CheckBox ID="chkBusiness" runat="server" Text="Business Division" CssClass="chkbox" />
</td>
<td>
<asp:DropDownList ID="ddlBusiness" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
CausesValidation="True" OnSelectedIndexChanged="ddlBusiness_SelectedIndexChanged"
ValidationGroup="grpSubmit" Width="350px">
<asp:ListItem Selected="True" Value="-1">--- SELECT ---</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvBusiness" runat="server" ControlToValidate="ddlBusiness"
ToolTip="Please select a Business." ErrorMessage="*" CssClass="required" Display="Dynamic"
ValidationGroup="grpSubmit" Enabled="false">
</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:PlaceHolder>
<hr size="1" />
<div style="text-align: center">
<table style="width: 10%">
<tr>
<td>
<asp:Button ID="btnHome" runat="server" Text="Home" OnClick="btnHome_Click" CssClass="btn" />
</td>
<td>
<asp:Button ID="btnSubmitReport" runat="server" Text="Submit" OnClick="btnSubmitReport_Click"
ValidationGroup="grpSubmit" CssClass="btn" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Try setting the Enabled attribute in the RequiredFieldValidator element to "True".
Below is a section of my site where the data is being loaded by a sql query in the code behind, which is listed below as well... My question is how can I duplicate the second < tr > in the < table > if there are more than one record returned in the code behind query... Any pointers or tips are appreciated...
--.aspx Table
`
<h2>Rebate Measures</h2>
<asp:Textbox ID="ProjectID" runat="server"></asp:Textbox>
<table border="1">
<tr style="background-color: beige">
<th>Delete</th>
<th>Packet #</th>
<th>EEC Ref #</th>
<th class="auto-style1">PTR Ref #</th>
<th>Residential Measure</th>
<th>PTCS</th>
<th>PTCS Ducts</th>
<th>PTCS Comm</th>
<th>Bus Bar KWh</th>
<th>Saved KWh</th>
<th>Msr Life</th>
<th>BPA Credit Rate</th>
<th>BPAtoFPUD Reimburse</th>
<th># of Units</th>
<th>Unit Type</th>
<th>Funding Source</th>
<th>Bid Cost</th>
<th>Customer Rebate</th>
</tr>
<tr style="background-color:#E0E0E0">
<td>
<asp:ImageButton Style="float:none; width: 20px; padding: 0; display: inline" ToolTip="Delete" OnClick="Delete_Click" ID="ImageButton1" ImageUrl="Images/DeletePage.gif" runat="server"></asp:ImageButton>
</td>
<td>
<asp:DropDownList ID="DropDownList1" CssClass="ddl" Width="60px" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList CssClass="ddl" ID="DropDownList2" Width="115px" OnTextChanged="EECNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td class="auto-style1">
<asp:TextBox ID="TextBox1" Width="100px" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" Width="350px" runat="server" Wrap="true" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" MaxLength="3" Columns="1" runat="server" Width="34px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Width="61px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Width="59px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox8" runat="server" Width="30px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox9" ReadOnly="true" runat="server" Width="78px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox10" BackColor="LightPink" runat="server" Width="128px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox11" TextMode="Number" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server" Width="40px"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList3" CssClass="ddl" runat="server">
<asp:ListItem Text="EA" Value="EA"></asp:ListItem>
<asp:ListItem Text="SqFt" Value="SqFt"></asp:ListItem>
<asp:ListItem Text="LnFt" Value="LnFt"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DropDownList4" CssClass="ddl" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server">
<asp:ListItem Text="EEI" Value="EEI" Selected="True"></asp:ListItem>
<asp:ListItem Text="Self" Value="Self"></asp:ListItem>
<asp:ListItem Text="Delta" Value="Delta"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="TextBox12" runat="server" Width="63px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox13" runat="server" Width="93px"></asp:TextBox>
</td>
</tr>
</table>
`
--Code Behind Query
string CS = ConfigurationManager.ConnectionStrings["CARD"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
String sql = "Select * from tbl_Measures_New1 Where Project_ID = #ProjectID and Project_ID like 'R%'";
SqlDataAdapter Msrda = new SqlDataAdapter(sql, con);
Msrda.SelectCommand.Parameters.AddWithValue("#ProjectID", ProjectID.Text);
DataSet Msrds = new DataSet();
Msrda.Fill(Msrds, "Msr");
ViewState["SQL"] = sql;
ViewState["Msr"] = Msrds;
if (Msrds.Tables["Msr"].Rows.Count > 0)
{
DataRow Msrdr = Msrds.Tables["Msr"].Rows[0];
AccountSelect.Text = Msrdr["Account_Num"].ToString();
OccCode.Text = Msrdr["Occ_Code"].ToString();
Measure.Text = Msrdr["Measure"].ToString();
Funding.SelectedValue = Msrdr["Funding_Source"].ToString();
PacketNum.Text = Msrdr["FPUD_Packet_No"].ToString();
EECNum.Text = Msrdr["EEC_Ref_Num"].ToString();
PTRNum1.Text = Msrdr["BPA_Ref_Num"].ToString();
VendorList.SelectedValue = Msrdr["Vendor_ID"].ToString();
SecVendorList.SelectedValue = Msrdr["Secondary_Vendor_ID"].ToString();
BidCost.Text = "$" + Msrdr["Measure_Cost"].ToString().Replace(".0000", ".00");
CustomerRebate.Text = "$" + Msrdr["Customer_Rebate"].ToString().Replace(".0000", ".00");
SavedKWh.Text = Msrdr["Saved_Kwh"].ToString();
Busbar.Text = Msrdr["BusBar_Kwh"].ToString();
BPACredit.Text = "$" + Msrdr["BPA_Credit"].ToString().Replace(".0000", ".00");
BPAReimburse.Text = "$" + Msrdr["BPA-FPUD_Reimburse"].ToString().Replace(".0000", ".00");
Units.Text = Msrdr["Measure_Units"].ToString();
if (Units.Text != "")
{
Units.Text = Msrdr["Measure_Units"].ToString();
}
else
{
Units.Text = "1";
}
UnitType.SelectedValue = Msrdr["Unit_Type"].ToString();
MsrLife.Text = Msrdr["Measure_Life"].ToString();
PTCS.Text = Msrdr["PTCS"].ToString();
Ducts.Text = Msrdr["PTCS_Ducts"].ToString();
Comm.Text = Msrdr["PTCS_Comm"].ToString();
}
There are a few ways to do this. Look into the Repeater control if you want to use a table like this, or look into using a GridView and binding your result set to that. (It is possible to have a dropdowns and textboxes inside of a GridView.)
Also, make sure your code validates ProjectID.Text to avoid any potential SQL injection issues!
Posted is an abridged code of my user control. I have added an update panel over radio button and want to execute a server function which will toggle between consultant drop down list and reference name text box based on the selection without a full post back. But the radio button is causing a full postback. What am I doing wrong here?
<aj:ModalPopupExtender ID="ModalPopup1" runat="server" PopupControlID="Panel1"
BackgroundCssClass="PopupBackground" CancelControlID="closeButton">
</aj:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="PopupPanel" align="center" style = "display:none">
<h1 class="PopupHeading">Add New Candidate</h1>
<table class="PopupTable">
<tr>
<td>
<asp:Label ID="firstNameLabel" runat="server" Text="First Name" CssClass="PopupLabel"></asp:Label>
</td>
<td>
<asp:TextBox ID="firstNameTextBox" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
<td class="ValidationError">
<asp:RequiredFieldValidator ID="nameRequiredFieldValidator" runat="server"
ValidationGroup="AddCandidateValidationGroup"
ErrorMessage="Name is required" Text="*"
ControlToValidate="firstNameTextBox" CssClass="failureNotification">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="emailLabel" runat="server" Text="Email" CssClass="PopupLabel"></asp:Label>
</td>
<td>
<asp:TextBox ID="emailTextBox" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ValidationGroup="AddCandidateValidationGroup"
ErrorMessage="Email is required" Text="*"
ControlToValidate="emailTextBox" CssClass="failureNotification">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:RegularExpressionValidator ID="emailRegularExpressionValidator"
runat="server" ErrorMessage="Incorrect Email"
ValidationGroup="AddCandidateValidationGroup"
ControlToValidate="emailTextBox"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
CssClass="failureNotification" Text="Incorrect email">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="referredByLabel" runat="server" Text="Referred By" CssClass="PopupLabel"></asp:Label>
</td>
<td>
<asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:RadioButtonList ID="RefConsRadButList" runat="server" AutoPostBack="true"
RepeatDirection="Horizontal" OnSelectedIndexChanged="RefConsRadButList_SelectedIndexChanged" CausesValidation="false">
<asp:ListItem >Consultant</asp:ListItem>
<asp:ListItem>Referral</asp:ListItem>
<asp:ListItem Selected="True">N/A</asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RefConsRadButList" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="consultantNameLabel" runat="server" Text="Consultant Name" Visible="false" CssClass="PopupLabel"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ConsultantDrDoList" runat="server" Visible="false">
<asp:ListItem>Select Consultant</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="referenceNameLabel" runat="server" Text="Reference Name" Visible = "false" CssClass="PopupLabel"></asp:Label>
</td>
<td>
<asp:TextBox ID="ReferralNameTextBox" runat="server" Visible="false"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="refNameRequiredFieldValidator" runat="server"
ValidationGroup="AddCandidateValidationGroup"
ErrorMessage="Referral name is required" Text="*"
ControlToValidate="phoneTextBox" CssClass="failureNotification">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<br />
<asp:Button ID="addButton" runat="server" Text="Add" onclick="addButton_Click" ValidationGroup="AddCandidateValidationGroup"/>
<asp:Button ID="closeButton" runat="server" Text="Close" />
<div id="AddStatus">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ValidationGroup="AddCandidateValidationGroup"
HeaderText="Add user failed due to the following errors:" CssClass="PopupValidationError"/>
</div>
</asp:Panel>
instead of using updatepanel on modalpopup panel you can try something from code behind to serve the purpose.
<asp:scriptmanager id="ScriptManager1" runat="server">
</asp:scriptmanager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
CancelControlID="btnCancel" PopupControlID="Panel1"
TargetControlID="HiddenField1">
</asp:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="Panel">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="34px" RepeatDirection="Horizontal"
Width="129px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>Option1</asp:ListItem>
<asp:ListItem>Option2</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txt1" runat="server"
Visible="False"></asp:TextBox>
<asp:TextBox ID="txt2" runat="server"
Visible="False"></asp:TextBox>
</asp:Panel>
===========================================
Code Behind:
===========================================
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
txt1.Visible = true;
ModalPopupExtender1.Show();
}
else
{
txt2.Visible = true;
ModalPopupExtender1.Show();
}
}
I'm trying to implement validation in my ASP.NET Webforms application. Right now, the only validator that works is for the Date of Birth (DOB) field. It is a custom field.
ASPX Code
<table>
<tr> <td align="center" colspan="2">
<asp:Label ID="RegisterTitleID" runat="server">Register here for your New Account </asp:Label></td>
</tr>
<tr>
<td align="right"> <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="EmailTextBox">E-mail:</asp:Label> </td>
<td> <asp:TextBox ID="EmailTextBox" runat="server" Height="25px" Width="200px"
CausesValidation="True"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="EmailTextBox" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="RegistrationWizard"
Display="Dynamic">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="PasswordTextBox">Password:</asp:Label> </td>
<td> <asp:TextBox ID="PasswordTextBox" runat="server" TextMode="Password"
Height="25px" Width="200px" CausesValidation="True"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="PasswordTextBox" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="RegistrationWizard"
Display="Dynamic">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="right"> <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPasswordTextBox">Confirm Password:</asp:Label> </td>
<td> <asp:TextBox ID="ConfirmPasswordTextBox" runat="server" TextMode="Password" Height="25px" Width="200px"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPasswordTextBox" ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="PasswordTextBox" ControlToValidate="ConfirmPasswordTextBox"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="RegistrationWizard"> </asp:CompareValidator> </td> </tr>
<tr>
<td align="right"> <asp:Label ID="TitleLabel" runat="server" AssociatedControlID="TitleTextBox">Title:</asp:Label> </td>
<td> <asp:TextBox ID="TitleTextBox" runat="server" Height="25px" Width="200px"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="TitleRequired" runat="server"
ControlToValidate="TitleTextBox" ErrorMessage="Title is required."
ToolTip="Title is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="right"> <asp:Label ID="FirstNameLabel" runat="server" AssociatedControlID="FirstNameTextBox">First Name:</asp:Label> </td>
<td> <asp:TextBox ID="FirstNameTextBox" runat="server" Height="25px" Width="200px"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server"
ControlToValidate="FirstNameTextBox" ErrorMessage="First Name is required."
ToolTip="First Name is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="right"> <asp:Label ID="SurnameLabel" runat="server" AssociatedControlID="SurnameTextBox">Surname:</asp:Label> </td>
<td> <asp:TextBox ID="SurnameTextBox" runat="server" Height="25px" Width="200px"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="SurnameRequired" runat="server"
ControlToValidate="SurnameTextBox" ErrorMessage="Surname is required."
ToolTip="Surname is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator> </tr>
<tr>
<td align="right"> <asp:Label ID="DOBLabel" runat="server" AssociatedControlID="DOBTextBox">Date of Birth:</asp:Label> </td>
<td> <asp:TextBox ID="DOBTextBox" runat="server" Height="25px" Width="200px">dd/mm/yyyy</asp:TextBox>
</td>
<asp:RequiredFieldValidator ID="DOBRequired" runat="server"
ControlToValidate="DOBTextBox" ErrorMessage="Date of birth is required."
ToolTip="Date of birth is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator>
<asp:CustomValidator runat="server"
ID="DateRangeCustomValidator"
ControlToValidate="DOBTextBox"
onservervalidate="valDateRange_ServerValidate"
ErrorMessage="Enter a valid date. " />
</tr>
<tr>
<td align="right"> <asp:Label ID="GenderLabel" runat="server" AssociatedControlID="GenderDropDownList">Gender:</asp:Label> </td>
<td> <asp:DropDownList ID="GenderDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList> </td>
<asp:RequiredFieldValidator ID="GenderRequired" runat="server"
ControlToValidate="GenderDropDownList" ErrorMessage="Gender is required."
ToolTip="Gender is required." ValidationGroup="RegistrationWizard">*</asp:RequiredFieldValidator>
</tr>
<tr>
<td align="right"> <asp:Label ID="PhoneNumberLabel" runat="server" AssociatedControlID="PhoneNumberTextBox">PhoneNumber:</asp:Label> </td>
<td> <asp:TextBox ID="PhoneNumberTextBox" runat="server" Height="25px" Width="200px"></asp:TextBox></td></tr>
<tr>
<td align="right"> <asp:Label ID="FavouriteTeamLabel" runat="server" AssociatedControlID="FavouriteTeamDropDownList">Favourite Team:</asp:Label> </td>
<td>
<asp:DropDownList ID="FavouriteTeamDropDownList" runat="server" DataSourceID="Team"
DataTextField="Team" DataValueField="Team" Height="27px" Width="205px">
</asp:DropDownList>
<asp:SqlDataSource ID="Team" runat="server"
ConnectionString="<%$ ConnectionStrings:RocoSportsDBConnectionString %>"
SelectCommand="SELECT [Team] FROM [Team]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td align="right"> <asp:Label ID="MaritialStatusLabel" runat="server" AssociatedControlID="MaritialStatusDropDownList">Maritial Status:</asp:Label> </td>
<td> <asp:DropDownList ID="MaritialStatusDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>Single</asp:ListItem>
<asp:ListItem>Married</asp:ListItem>
<asp:ListItem>Separated</asp:ListItem>
<asp:ListItem>Unmarried Relationship</asp:ListItem>
<asp:ListItem>Domestic Partnership</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right"> <asp:Label ID="EducationLabel" runat="server" AssociatedControlID="EducationDropDownList">Education:</asp:Label> </td>
<td> <asp:DropDownList ID="EducationDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Primary School</asp:ListItem>
<asp:ListItem>Secondary School</asp:ListItem>
<asp:ListItem>College</asp:ListItem>
<asp:ListItem>Undergrad</asp:ListItem>
<asp:ListItem>Postgrad</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right"> <asp:Label ID="ProfessionLabel" runat="server" AssociatedControlID="ProfessionDropDownList">Profession:</asp:Label> </td>
<td> <asp:DropDownList ID="ProfessionDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Management</asp:ListItem>
<asp:ListItem>Professional</asp:ListItem>
<asp:ListItem>Armed Forces</asp:ListItem>
<asp:ListItem>Sales</asp:ListItem>
<asp:ListItem>Adminstrative</asp:ListItem>
<asp:ListItem>Farming</asp:ListItem>
<asp:ListItem>Construction</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right"> <asp:Label ID="SalaryLabel" runat="server" AssociatedControlID="SalaryDropDownList">Salary:</asp:Label> </td>
<td> <asp:DropDownList ID="SalaryDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>5000</asp:ListItem>
<asp:ListItem>10000</asp:ListItem>
<asp:ListItem>20000</asp:ListItem>
<asp:ListItem>30000</asp:ListItem>
<asp:ListItem>50000</asp:ListItem>
<asp:ListItem>100000</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right"> <asp:Label ID="EmploymentStatusLabel" runat="server" AssociatedControlID="EmploymentStatusDropDownList">EmploymentStatus:</asp:Label> </td>
<td> <asp:DropDownList ID="EmploymentStatusDropDownList" runat="server" AppendDataBoundItems="true" Height="27px" Width="205px">
<asp:ListItem Value="-1">Select</asp:ListItem>
<asp:ListItem>Unemployed</asp:ListItem>
<asp:ListItem>Employed</asp:ListItem>
<asp:ListItem>Self-employed</asp:ListItem>
<asp:ListItem>Volunteer</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right"> <asp:Label ID="InterestsLabel" runat="server" AssociatedControlID="InterestsCheckBox">Interests:</asp:Label> </td>
<td>
<asp:CheckBoxList ID="InterestsCheckBox" runat="server"
onselectedindexchanged="InterestsCheckBox_SelectedIndexChanged">
<asp:ListItem>Reading</asp:ListItem>
<asp:ListItem>Football</asp:ListItem>
<asp:ListItem>Swimming</asp:ListItem>
<asp:ListItem>Basketball</asp:ListItem>
<asp:ListItem>Cooking</asp:ListItem>
<asp:ListItem>Music</asp:ListItem>
<asp:ListItem>Philosophy</asp:ListItem>
<asp:ListItem>Programming</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr> <td align="center" colspan="2" style="color:Red;"> <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> </td> </tr>
<tr> <td align="center" colspan="2"> <asp:Button ID="RegisterButton" runat="server" Text="Register" onclick="registerbutton_Click"/> </td> </tr>
</table>
What could be the problem that's causing this code not to work, yet is not throwing any errors? Also, I'd like to position the validators better, and add color to them?
You are using a ValidationGroup for all your validators except the DOB Custom validator.
Add it to your custom validator and also the Register Button.
<asp:CustomValidator runat="server"
ID="DateRangeCustomValidator"
ControlToValidate="DOBTextBox"
onservervalidate="valDateRange_ServerValidate"
ErrorMessage="Enter a valid date. "
ValidationGroup="RegistrationWizard"/>
<asp:Button ID="RegisterButton" runat="server" Text="Register"
ValidationGroup="RegistrationWizard" onclick="registerbutton_Click"/>
You have ValidationGroup set on your validators but not on your button.