0

Hello

I am trying to give focus to a text box on a form:

Protected Sub Page_Load(ByVal sender As Object, _
   ByVal e As System.EventArgs)
        username.Focus()
    End Sub

I know the syntax is correct because I use it elsewhere. However, I am getting the following error (please see attached) with Page_Load: 'Protected Sub Page_Load....has multiple definitions with identical signatures'.

Does this mean I can only have one 'Protected Sub Page_Load' per aspx file? And what would I replace it with?

Thank you.

Attachments Page_Load.jpg 62.22 KB
3
Contributors
4
Replies
21
Views
3 Years
Discussion Span
Last Post by Blueie
1

Yes you would only have one subroutine handling the page load event.

Move the username.Focus() code to the page load routing you are keeping.

Within the subroutine, you need to determine where you want that code to run. It can be the first, last line or anywhere in that block of code since Focus() isn't related to anything else in that block.

Edited by JorgeM

Votes + Comments
Informative reply that works!
0

Hello Jorge

Thanks for your reply.

Oh, I see. I have included it at the end of this script:

 Protected Sub Page_Load(ByVal sender As Object, e As EventArgs) Handles Me.Load
        RegisterHyperLink.NavigateUrl = "Register"
        OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")
        Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
        If Not [String].IsNullOrEmpty(returnUrl) Then
            RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & returnUrl
        End If
        **username.Focus()**
    End Sub

And there's the cursor nicely flashing away in the User Name field!

Thank you!

0

Hello Muhammad

Thanks for your reply.

Like this:

 Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
             'put your code here.
                     End Sub

By using 'Overrides', does that mean you can have more than one Page_Load per aspx file?

Thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.