-
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
-
Re: WithEvents problem
Why not just change the name of the button?
-
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
-
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.
-
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