SetFocusOnError Property of Validation Control in ASP.Net

Here, we learn how to use SetFocusOnError Property of Validation Control in ASP.Net.

All validation control has a SetFocusOnError property.

If you set SetFocusOnError=True  then when this validation control fail and show the error message then our mouse focus automatically that failed control.

If we use multiple validation controls, multiple validation controls fail then first validation control gets focus.

Here we take SetFocusOnError example with Requiredfieldvalidatior control.

how to use SetFocusOnError property in asp.net
how to use SetFocusOnError property in asp.net

The ASP.Net web form design code is :

<table>
<tr>
<td style="text-align: right">
Name :</td>
<td style="text-align: left">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td style="text-align: left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Enter Name !!"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="text-align: right">
City :</td>
<td style="text-align: left">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
<td style="text-align: left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter City !!"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td style="text-align: left">
<asp:Button ID="Button5" runat="server" Text="SAVE" />
</td>
<td>
&nbsp;</td>
</tr>
</table>
how to use SetFocusOnError property in asp.net
how to use SetFocusOnError property in asp.net
how to use SetFocusOnError property in asp.net
how to use SetFocusOnError property in asp.net

 

Leave a Reply

Your email address will not be published. Required fields are marked *