Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

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
0
Sams
Asked:
Sams
  • 2
1 Solution
 
rendlert07Commented:
txtbox.focus()
0
 
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

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now