Setfocus in using

I am coding a registeration form in using
i am checking the password and confirm password with compare validator.
after having checked the validity and if it does not match ,how do i set the
focus again to confirm password textbox control.
is there any builtin method for setfocus or i have to write acode.
thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Add a setfocus class to your project ( sample)

    Public Class SetFocus
        Public Shared Sub set_focus(ByRef p_page As System.Web.UI.Page, ByVal p_control As System.Web.UI.Control)
            Dim w_str As String
            If Not (p_control Is Nothing) Then
                w_str = "<script language=JavaScript>document.forms(0).elements['" & p_control.ClientID().ToString() & "'].focus();</script>"
                p_page.Controls.Add(New System.Web.UI.LiteralControl(w_str))
            End If
        End Sub
    End Class

then inside your validation procedure do something like:

          Dim comparer As CompareValidator = CType(item.FindControl("CompareValidator"), CompareValidator)


            ' Check for validation, if all valid, update the object to data entered and save it.
            If comparer.IsValid Then
'Do some stuff
    Dim SetFocus As New YourNameSpace.SetFocus()
SetFocus.set_focus(Me, txtbox)

Now you have a setfocus class that you can easily add and use in any project.
Bob LearnedCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by rendlert07

Please leave any comments here within the next seven days.


EE Cleanup Volunteer
rendlert07's answer is incorrect for an application.  .setfocus on works for winforms.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.