Validators - error message not showing when JS disabled & only server side validation occurs

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>

<asp:DataGrid 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>
</asp:DataGrid>

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;
 
T

TS

I think I fixed it...the page was getting reloaded with most up to date
saved data after failing the validation. I don't know why, but i think its
because the value of the controls were back to a safe value by the time the
page came back EVEN though validation failed.

Is this a correct analysis of why the messages are now appearing? It seems
like maybe if the validator failed, it would always show the message??

thanks

TS said:
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>

<asp:DataGrid 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>
</asp:DataGrid>

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;
 
W

Walter Wang [MSFT]

Hi,

Thank you for your post.

I think your analysis on this issue is correct.

Normally, a Page's life cycle is:
1) POST Request is issued by client
2) Page-derived class is created, constructor is invoked
3) IHttpHandler.ProcessRequest is invoked (implemented by Page)
4) Page.Init()
5) Page.CreateChildControls()
6) Server-side control state is restored from POST variables and VIEWSTATE
7) Page.Load()
8) Page.Validate()
9) Server-side control events are fired
10) Page.PreRender()
11) Page.Render()
12) Page.RenderChildren()
13) HTTP Response is issued to client
14) Page.Unload()
15) Instance of Page-derived class is discarded

When you disabled client-side javascript, the client-side validation
doesn't work and a postback must be performed to validate on the server
side. From above event order, you will see that Page.Validate() occured
after Page.Load(), is there any chance that you're rebinding the DataGrid
in Page.Load()?


Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,375
Members
47,020
Latest member
anuradha

Latest Threads

Top