Validator & Layout problem

J

Jeff

hey

asp.net 2.0

I'm trying to create a web page where users can register to my web portal.
But I've run into a layout problem when using the data validator classes.
The problem is that the error message is not displayed on the same row as
the control it's validating. Check this link and you see an example of the
problem: http://home.online.no/~au-holme/pub/14506/problem.GIF the text
"Password and confirm password must match" is not displayed on the same row
as the control it is set to validate. And also the error isn't left
aligned, but HorizontalAlign is set to "Left" - so I hoped the text should
be left aligned

What am I doing wrong here?

Below are the markup of my problem table

<asp:Table ID="Table1" runat="server" CellPadding="2" Width="100%"
BorderStyle="Solid" BorderColor="Green" BorderWidth="2">
<asp:TableRow>
<asp:TableCell CssClass="fieldname"
Width="180">UserName:</asp:TableCell>
<asp:TableCell Width="200" ><asp:TextBox ID="UserName" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px">
<asp:RequiredFieldValidator ID="valRequireUserName" runat="server"
ControlToValidate="UserName" SetFocusOnError="true" Display="Dynamic"
ErrorMessage="Username is required." ToolTip="Username is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderStyle="Solid"
BorderColor="BlueViolet" BorderWidth="2">Password:</asp:TableCell>
<asp:TableCell Width="200" BorderStyle="Solid" BorderWidth="2"
BorderColor="DarkRed"><asp:TextBox ID="Password" runat="server"
TextMode="Password" Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px">
<asp:RequiredFieldValidator ID="valRequiredPassword" runat="server"
ErrorMessage="Password is required" ValidationGroup="CreateUserWizard1"
ControlToValidate="password"></asp:RequiredFieldValidator>
<%--<asp:RegularExpressionValidator ID="valPasswordLength" runat="server"
ErrorMessage="Password too short" Display="Dynamic"
ValidationGroup="CreateUserWizard1" ControlToValidate="Password"
ValidationExpression="\w{5,}"></asp:RegularExpressionValidator>--%>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180">Confirm
password:</asp:TableCell>
<asp:TableCell Width="200" BorderStyle="Solid" BorderColor="CadetBlue"
BorderWidth="2"><asp:TextBox ID="Confirmpassword" runat="server"
TextMode="Password" Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px" BorderStyle="Solid"
BorderColor="Beige" BorderWidth="2">
<asp:RequiredFieldValidator ID="valRequiredConfirmPassword" runat="server"
ErrorMessage="Confirm password is required"
ControlToValidate="Confirmpassword"
ValidationGroup="CreateUserWizard1"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="valComparePasswords" runat="server"
ErrorMessage="Password and confirm password must match"
ValidationGroup="CreateUserWizard1" ControlToCompare="Password"
SetFocusOnError="true"
ControlToValidate="Confirmpassword"></asp:CompareValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderColor="Red"
BorderStyle="Solid" BorderWidth="2">E-mail:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Email" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireEmail" runat="server"
ErrorMessage="E-mail is required" ControlToValidate="Email"
ValidationGroup="CreateUserWizard1"
SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="valEmailPattern" runat="server"
ErrorMessage="The E-mail is not well-formed" Display="Dynamic"
ControlToValidate="Email" ValidationGroup="CreateUserWizard1"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</asp:TableCell>
</asp:TableRow>


<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180">Security
question:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Question" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireQuestion" runat="server"
ErrorMessage="Security question is required"
ValidationGroup="CreateUserWizard1" ControlToValidate="Question"
SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderColor="Brown"
BorderStyle="Solid" BorderWidth="2">Security answer:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Answer" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireAnswar" runat="server"
ErrorMessage="Security answer is required" Display="Dynamic"
SetFocusOnError="true" ValidationGroup="CreateUserWizard1"
ControlToValidate="Answer"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
 
J

Jeff

I've solved it, well I had to redesign the layout.


Jeff said:
hey

asp.net 2.0

I'm trying to create a web page where users can register to my web portal.
But I've run into a layout problem when using the data validator classes.
The problem is that the error message is not displayed on the same row as
the control it's validating. Check this link and you see an example of the
problem: http://home.online.no/~au-holme/pub/14506/problem.GIF the text
"Password and confirm password must match" is not displayed on the same
row as the control it is set to validate. And also the error isn't left
aligned, but HorizontalAlign is set to "Left" - so I hoped the text should
be left aligned

What am I doing wrong here?

Below are the markup of my problem table

<asp:Table ID="Table1" runat="server" CellPadding="2" Width="100%"
BorderStyle="Solid" BorderColor="Green" BorderWidth="2">
<asp:TableRow>
<asp:TableCell CssClass="fieldname"
Width="180">UserName:</asp:TableCell>
<asp:TableCell Width="200" ><asp:TextBox ID="UserName" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px">
<asp:RequiredFieldValidator ID="valRequireUserName" runat="server"
ControlToValidate="UserName" SetFocusOnError="true" Display="Dynamic"
ErrorMessage="Username is required." ToolTip="Username is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderStyle="Solid"
BorderColor="BlueViolet" BorderWidth="2">Password:</asp:TableCell>
<asp:TableCell Width="200" BorderStyle="Solid" BorderWidth="2"
BorderColor="DarkRed"><asp:TextBox ID="Password" runat="server"
TextMode="Password" Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px">
<asp:RequiredFieldValidator ID="valRequiredPassword" runat="server"
ErrorMessage="Password is required" ValidationGroup="CreateUserWizard1"
ControlToValidate="password"></asp:RequiredFieldValidator>
<%--<asp:RegularExpressionValidator ID="valPasswordLength" runat="server"
ErrorMessage="Password too short" Display="Dynamic"
ValidationGroup="CreateUserWizard1" ControlToValidate="Password"
ValidationExpression="\w{5,}"></asp:RegularExpressionValidator>--%>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180">Confirm
password:</asp:TableCell>
<asp:TableCell Width="200" BorderStyle="Solid" BorderColor="CadetBlue"
BorderWidth="2"><asp:TextBox ID="Confirmpassword" runat="server"
TextMode="Password" Width="200" /></asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="220px" BorderStyle="Solid"
BorderColor="Beige" BorderWidth="2">
<asp:RequiredFieldValidator ID="valRequiredConfirmPassword" runat="server"
ErrorMessage="Confirm password is required"
ControlToValidate="Confirmpassword"
ValidationGroup="CreateUserWizard1"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="valComparePasswords" runat="server"
ErrorMessage="Password and confirm password must match"
ValidationGroup="CreateUserWizard1" ControlToCompare="Password"
SetFocusOnError="true"
ControlToValidate="Confirmpassword"></asp:CompareValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderColor="Red"
BorderStyle="Solid" BorderWidth="2">E-mail:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Email" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireEmail" runat="server"
ErrorMessage="E-mail is required" ControlToValidate="Email"
ValidationGroup="CreateUserWizard1"
SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="valEmailPattern" runat="server"
ErrorMessage="The E-mail is not well-formed" Display="Dynamic"
ControlToValidate="Email" ValidationGroup="CreateUserWizard1"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</asp:TableCell>
</asp:TableRow>


<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180">Security
question:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Question" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireQuestion" runat="server"
ErrorMessage="Security question is required"
ValidationGroup="CreateUserWizard1" ControlToValidate="Question"
SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell CssClass="fieldname" Width="180" BorderColor="Brown"
BorderStyle="Solid" BorderWidth="2">Security answer:</asp:TableCell>
<asp:TableCell Width="200"><asp:TextBox ID="Answer" runat="server"
Width="200" /></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireAnswar" runat="server"
ErrorMessage="Security answer is required" Display="Dynamic"
SetFocusOnError="true" ValidationGroup="CreateUserWizard1"
ControlToValidate="Answer"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top