Focus using requiredfieldvalidator

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
rickydoyleAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Computer101Connect With a Mentor Commented:
PAQed, with points refunded (125)

Computer101
E-E Admin
0
 
rickydoyleAuthor Commented:
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
 
rickydoyleAuthor Commented:
I guess i figured it out, beause it is not doing the postback....thanks anyway though.  
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:

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
All Courses

From novice to tech pro — start learning today.