Setfocus in asp.net using vb.net

I am coding a registeration form in asp.net using vb.net.
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
SamsAsked:
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.

rendlert07Commented:
txtbox.focus()
0

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
MichITCommented:
Add a setfocus class to your project (vb.net 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)

            comparer.Validate()

            ' Check for validation, if all valid, update the object to data entered and save it.
            If comparer.IsValid Then
'Do some stuff
Else
    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.
0
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
MichITCommented:
rendlert07's answer is incorrect for an asp.net application.  .setfocus on works for winforms.

MichIT
0
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.