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.

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.

commented: Informative reply that works! +1

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!

you can override page_load event if you want.
protected override page_load etc etc.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.