How to give proper alignment of validator control's error messages in ASP c#.
Normally, we are using two validator (required validator
and regular expression validator) on email textbox, phone textbox and so on. Then
we are getting proper alignment problem like this:-



So in this article I am solving this problem using
display property. Display property refer to set the alignment. By default it is
static . Now we are change it dynamic for proper alignment. Like this :-



Source Code
with dynamic display property :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Email
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server"
ControlToValidate="txtemail" Display="Dynamic"
ErrorMessage="Please Enter email id" style="color: #FF0000"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator" runat="server"
ControlToValidate="txtemail" Display="Dynamic"
ErrorMessage="Please enter valid email id" style="color: #FF0000"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</div>
</form>
</body>
</html>
Out-put:-
How to give proper alignment of validator control's error messages in ASP c#.
Reviewed by NEERAJ SRIVASTAVA
on
5:39:00 PM
Rating:

No comments: