?
Solved

Focus using requiredfieldvalidator

Posted on 2003-03-18
4
Medium Priority
?
313 Views
Last Modified: 2012-08-14
Hey everyone,

I am trying to set focus to a textbox when a form is not properly validated.

This is my front end controls
<TR>
                                        <TD class="8V" vAlign="center"><asp:label id="lblUsername" Runat="server">Username</asp:label></TD>
                                        <TD class="8V" vAlign="center"><asp:textbox id="pUserName" Runat="server" Width="250" CssClass="8V"></asp:textbox><asp:RequiredFieldValidator ID="UnameValidate" controltovalidate="pUserName" Runat="server" ErrorMessage="Must enter username!"></asp:RequiredFieldValidator></TD>
                                   </TR>

This is the page behind code

If page.isvalid then
'do whatever
Else
    'try to set focus back up to pusername
     Me.SetFocus(Me.pUserName)

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
        Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"
        RegisterStartupScript("focus", s)
    End Sub
End If
0
Comment
Question by:rickydoyle
[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
4 Comments
 

Author Comment

by:rickydoyle
ID: 8160560
Why is it that on button click, this button click sub is not even getting called, what do i ahve to do differently here?
0
 

Author Comment

by:rickydoyle
ID: 8160801
I guess i figured it out, beause it is not doing the postback....thanks anyway though.  
0
 
LVL 96

Expert Comment

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

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9724325
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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