Click here to Skip to main content
16,004,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
firstly I describe situation:

From web page if i insert record successfully then no problem but if some error occur like email id already exist then it focus to the email id text box rather then other.

In .aspx

XML
<asp:TextBox ID="txtEmailId" runat="server" Width="30 %"  />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" Display="Dynamic" ValidationGroup="addClient"
                                runat="server" ErrorMessage="Please enter Email Id" ControlToValidate="txtEmailId"
                                Width="30 %" SetFocusOnError="true"></asp:RequiredFieldValidator>



In .aspx.cs

XML
catch (SqlException sql)
           {
               //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Email ID already exist !!!');window.location.href='ClientRegistraion.aspx';", true);
               Response.Write("<script language=javascript>alert('Email ID already exist !!!')</script>");
               txtEmailId.Focus();
               RequiredFieldValidator7.Enabled = true;

           }




thanks in advance.
Posted
Updated 14-May-13 1:59am
v3
Comments
ZurdoDev 14-May-13 7:43am    
Just write code to do it? Where are you stuck?
Pr@senJeeT 14-May-13 7:53am    
I wrote the code but my problem is that after display message like "Email ID already exist" after that i did not set focus on email textbox.
ZurdoDev 14-May-13 7:54am    
Use improve question and post the relevant code.
Pr@senJeeT 14-May-13 8:00am    
it did not focus to email id textbox.
Thanks7872 14-May-13 8:05am    
try setting focus to any other control or anywhere else.

1 solution

I see that you have SetFocusOnError="true" propery set for RequiredFieldValidator.
since it is set when there is validation failure, focus will be set to the control which failed in validation. Set SetFocusOnError="false", if you wish to change that behaviour.
 
Share this answer
 
v2
Comments
Maciej Los 14-May-13 17:09pm    
Actually it is not a problem. Please, see this comment:
Pr@senJeeT - 7 hrs ago
yes Mr.Tadit Dash but the problem is that it did not show message of requird field.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900