CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Posts
    24

    WithEvents problem

    This is ASP.net related, but since the .vb file is giving me the problem I figure this is the board to post on, sorry in advance if it isn't!

    So I'm making a Log in type screen for use in a web browser, and I'm having a little bit of a problem with the attached .vb file. I get an error on the line

    'Protected WithEvents submit As New Button'

    Error says submit is already declared... Although dropping this line gives me a handler error because of the lack of a WithEvents statement...

    Heres the larger picture for your understanding:


    Public Class _Default
    Inherits System.Web.UI.Page

    Protected WithEvents submit As New Button


    Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click

    Dim strscript As String = "<script language='javascript' src='a.js'></script>"
    strscript += "<script>"
    strscript += "CustomVal()"
    strscript += "</script>"

    Page.RegisterStartupScript("strscript", strscript)

    End Sub

    End Class

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: WithEvents problem

    Why not just change the name of the button?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Sep 2010
    Posts
    24

    Re: WithEvents problem

    Because the WithEvents has to match the actual name of the button, right? no matter what name i set the button to I'd have to name the WithEvents to the same thing, unless I understand that wrong

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: WithEvents problem

    If you are defining an object you have control over the name.
    Yes the with events is part of the definition and will use the same name.
    If the object already exists then you can not define it in this manner as it already exists.

    Sounds like you have a button named submit and then are trying to create a new button named submit. This will not work.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Sep 2010
    Posts
    24

    Re: WithEvents problem

    This is true. I do already have a button called submit... but how do I place the once I'm making in VB.NET then? The exisiting button is an <asp:button> in a particular location on the page, if I can place it through VB I can get rid of the asp one

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured