T
TS
Hi, i am stuck on this scenario. I have a datagrid that has validators in
its item template and a validation summary on the page. When js is enabled
and incorrect data is inputted, the messages appear in the val summary. When
i disable JS, the validators' message won't appear. anyone know why?
thanks
<asp:ValidationSummary ID="valSummary" Runat="server"
CssClass="validationSummary" ShowMessageBox="False"></asp:ValidationSummary>
<aspataGrid id="dgRoles" Runat="server" CssClass="dataGrid"
DataKeyField="StaffRoleId" AutoGenerateColumns="False"
ShowFooter="True">
<AlternatingItemStyle CssClass="alt"></AlternatingItemStyle>
<HeaderStyle CssClass="header"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Staff Role">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StaffRoleDescription") %>
</ItemTemplate>
<EditItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StaffRoleDescription") %>
</EditItemTemplate>
<FooterTemplate>
<asp:dropdownlist id="ddlRole" DataTextField="Desc_Short"
DataValueField="Staff_Role_Cd" Runat="server"></asp:dropdownlist>
<asp:RequiredFieldValidator ID="rfvRole" ControlToValidate="ddlRole"
Runat="server" ErrorMessage="Staff Role is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Certified/Qualified">
<ItemTemplate>
<%# (bool)DataBinder.Eval(Container.DataItem, "IsCertified") ? "Yes" :
"No" %>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList id="rblCertified" Runat="server"
RepeatDirection="Horizontal" CssClass="radioButtonList">
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvCertified"
ControlToValidate="rblCertified" Runat="server"
ErrorMessage="Certified/Qualified is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButtonList id="rblCertified" Runat="server"
RepeatDirection="Horizontal" CssClass="radioButtonList">
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvCertified"
ControlToValidate="rblCertified" Runat="server"
ErrorMessage="Certified/Qualified is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="% Time in Role">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "PercentTimeInRole") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox id="txtPercentInRole" Runat="server" MaxLength="3"
Columns="3" CssClass="textbox"></asp:textbox>
<asp:RequiredFieldValidator ID="rfvPercentInRole" Runat="server"
ErrorMessage="Percent time in Role is required."
ControlToValidate="txtPercentInRole" CssClass="validator"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvPercentInRole" Runat="server" Type="Integer"
MinimumValue="1" MaximumValue="100"
ErrorMessage="Percent time in Role must be a whole number between 1 and
100." ControlToValidate="txtPercentInRole"
CssClass="validator" Display="Dynamic">*</asp:RangeValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox id="txtPercentInRole" Runat="server" MaxLength="3"
Columns="3" CssClass="textbox"></asp:textbox>
<asp:RequiredFieldValidator ID="rfvPercentInRole" Runat="server"
ErrorMessage="Percent time in Role is required."
ControlToValidate="txtPercentInRole" CssClass="validator"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvPercentInRole" Runat="server" Type="Integer"
MinimumValue="1" MaximumValue="100"
ErrorMessage="Percent time in Role must be a whole number between 1 and
100." ControlToValidate="txtPercentInRole"
CssClass="validator" Display="Dynamic">*</asp:RangeValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btnEdit" Runat="server" CommandName="Edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Edit" />
<asp:Button ID="btnEditUpdate" Runat="server" CommandName="EditUpdate"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Save" />
<asp:Button ID="btnEditCancel" Runat="server" CommandName="EditCancel"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Cancel" CausesValidation="False" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" Runat="server" CommandName="Add" Text="Add" />
<asp:Button ID="btnAddSave" Runat="server" CommandName="AddSave"
Text="Save" />
<asp:Button ID="btnAddCancel" Runat="server" CommandName="AddCancel"
Text="Cancel" CausesValidation="False" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="btnDelete" Runat="server" CommandName="Delete"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Delete" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
protected void dgRoles_ItemCommand(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs args)
{
switch (args.CommandName)
{
case "AddSave":
RequiredFieldValidator rfvRole = (RequiredFieldValidator)
args.Item.FindControl("rfvRole");
if(WebHelper.ValidatorsAreValid(rfvRole))
{
// See if the selected role has already been added.
DropDownList ddlRole = (DropDownList)
args.Item.FindControl("ddlRole");
staffRoleId = int.Parse(ddlRole.SelectedValue);
staffRoleDescription = StaffRole.GetDescriptionForId(staffRoleId);
// Save the role unless someone else has already added it.
if (staffRoles.Contains(staffRoleId))
{
this.messageBox.AddFailureMessage("Failed to add {0} for {1}. It has
already been added (possibly by another user).", staffRoleDescription,
this.SelectedStaff.FullName);
}
else
{
SaveRole(args);
}
// Get out of add mode.
this.AddMode = false;
// Show the delete buttons.
this.dgRoles.Columns[DataGridDeleteColumnIndex].Visible = true;
}
break;
its item template and a validation summary on the page. When js is enabled
and incorrect data is inputted, the messages appear in the val summary. When
i disable JS, the validators' message won't appear. anyone know why?
thanks
<asp:ValidationSummary ID="valSummary" Runat="server"
CssClass="validationSummary" ShowMessageBox="False"></asp:ValidationSummary>
<aspataGrid id="dgRoles" Runat="server" CssClass="dataGrid"
DataKeyField="StaffRoleId" AutoGenerateColumns="False"
ShowFooter="True">
<AlternatingItemStyle CssClass="alt"></AlternatingItemStyle>
<HeaderStyle CssClass="header"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Staff Role">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StaffRoleDescription") %>
</ItemTemplate>
<EditItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StaffRoleDescription") %>
</EditItemTemplate>
<FooterTemplate>
<asp:dropdownlist id="ddlRole" DataTextField="Desc_Short"
DataValueField="Staff_Role_Cd" Runat="server"></asp:dropdownlist>
<asp:RequiredFieldValidator ID="rfvRole" ControlToValidate="ddlRole"
Runat="server" ErrorMessage="Staff Role is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Certified/Qualified">
<ItemTemplate>
<%# (bool)DataBinder.Eval(Container.DataItem, "IsCertified") ? "Yes" :
"No" %>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList id="rblCertified" Runat="server"
RepeatDirection="Horizontal" CssClass="radioButtonList">
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvCertified"
ControlToValidate="rblCertified" Runat="server"
ErrorMessage="Certified/Qualified is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButtonList id="rblCertified" Runat="server"
RepeatDirection="Horizontal" CssClass="radioButtonList">
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvCertified"
ControlToValidate="rblCertified" Runat="server"
ErrorMessage="Certified/Qualified is required."
CssClass="validator" Display="Dynamic">*</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="% Time in Role">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "PercentTimeInRole") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox id="txtPercentInRole" Runat="server" MaxLength="3"
Columns="3" CssClass="textbox"></asp:textbox>
<asp:RequiredFieldValidator ID="rfvPercentInRole" Runat="server"
ErrorMessage="Percent time in Role is required."
ControlToValidate="txtPercentInRole" CssClass="validator"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvPercentInRole" Runat="server" Type="Integer"
MinimumValue="1" MaximumValue="100"
ErrorMessage="Percent time in Role must be a whole number between 1 and
100." ControlToValidate="txtPercentInRole"
CssClass="validator" Display="Dynamic">*</asp:RangeValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox id="txtPercentInRole" Runat="server" MaxLength="3"
Columns="3" CssClass="textbox"></asp:textbox>
<asp:RequiredFieldValidator ID="rfvPercentInRole" Runat="server"
ErrorMessage="Percent time in Role is required."
ControlToValidate="txtPercentInRole" CssClass="validator"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvPercentInRole" Runat="server" Type="Integer"
MinimumValue="1" MaximumValue="100"
ErrorMessage="Percent time in Role must be a whole number between 1 and
100." ControlToValidate="txtPercentInRole"
CssClass="validator" Display="Dynamic">*</asp:RangeValidator>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btnEdit" Runat="server" CommandName="Edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Edit" />
<asp:Button ID="btnEditUpdate" Runat="server" CommandName="EditUpdate"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Save" />
<asp:Button ID="btnEditCancel" Runat="server" CommandName="EditCancel"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Cancel" CausesValidation="False" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" Runat="server" CommandName="Add" Text="Add" />
<asp:Button ID="btnAddSave" Runat="server" CommandName="AddSave"
Text="Save" />
<asp:Button ID="btnAddCancel" Runat="server" CommandName="AddCancel"
Text="Cancel" CausesValidation="False" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="btnDelete" Runat="server" CommandName="Delete"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "StaffRoleId") %>'
Text="Delete" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
protected void dgRoles_ItemCommand(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs args)
{
switch (args.CommandName)
{
case "AddSave":
RequiredFieldValidator rfvRole = (RequiredFieldValidator)
args.Item.FindControl("rfvRole");
if(WebHelper.ValidatorsAreValid(rfvRole))
{
// See if the selected role has already been added.
DropDownList ddlRole = (DropDownList)
args.Item.FindControl("ddlRole");
staffRoleId = int.Parse(ddlRole.SelectedValue);
staffRoleDescription = StaffRole.GetDescriptionForId(staffRoleId);
// Save the role unless someone else has already added it.
if (staffRoles.Contains(staffRoleId))
{
this.messageBox.AddFailureMessage("Failed to add {0} for {1}. It has
already been added (possibly by another user).", staffRoleDescription,
this.SelectedStaff.FullName);
}
else
{
SaveRole(args);
}
// Get out of add mode.
this.AddMode = false;
// Show the delete buttons.
this.dgRoles.Columns[DataGridDeleteColumnIndex].Visible = true;
}
break;