Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Validators - error message not showing when JS disabled & only server side validation occurs

Reply
Thread Tools

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

 
 
TS
Guest
Posts: n/a
 
      06-19-2006
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;


 
Reply With Quote
 
 
 
 
TS
Guest
Posts: n/a
 
      06-19-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
>



 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      06-20-2006
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()
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation Summary not showing for client side validation cwhankey@gmail.com ASP .Net 1 12-12-2008 02:32 AM
Button disabled and re-enabled in client side not firing server-side click event. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= ASP .Net 2 05-27-2008 09:57 AM
Server-side events do not fire the first time after client-side validators have fired Stuart Whiteford ASP .Net 2 04-25-2006 10:10 AM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Dynamically created validators - server side validation not working. Tony ASP .Net 1 12-12-2003 11:58 AM



Advertisments