?
Solved

Setfocus in asp.net using vb.net

Posted on 2003-03-27
5
Medium Priority
?
551 Views
Last Modified: 2006-11-17
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
Comment
Question by:Sams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
rendlert07 earned 160 total points
ID: 8227048
txtbox.focus()
0
 

Expert Comment

by:MichIT
ID: 8227068
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9725491
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
 

Expert Comment

by:MichIT
ID: 9734879
rendlert07's answer is incorrect for an asp.net application.  .setfocus on works for winforms.

MichIT
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question