Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Button created with dim new button click event is not working

Reply
Thread Tools

Button created with dim new button click event is not working

 
 
gce
Guest
Posts: n/a
 
      04-11-2005
Allthough button2 created with the designer works 100%. The button I created
(inside the table) with dim button1 as new button doesn't give me a click
event. Please help.

Public Class WebForm8

Inherits System.Web.UI.Page


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Table1 As System.Web.UI.WebControls.Table
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim rij1 As New TableRow
Dim cel1 As New TableCell
Dim cel2 As New TableCell

Dim header As New TableHeaderCell
header.RowSpan = 1
header.ColumnSpan = 2
header.Text = "test"
header.Font.Bold = True
header.HorizontalAlign = HorizontalAlign.Center
header.VerticalAlign = VerticalAlign.Middle

Dim headerrow As New TableRow
headerrow.Cells.Add(header)

Table1.Rows.Add(headerrow)

Dim button1 As New Button

button1.Text = "knop"

cel1.Controls.Add(button1)
cel2.Text = "cel2"
rij1.Cells.Add(cel1)
rij1.Cells.Add(cel2)

Table1.Rows.Add(rij1)




End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim popupScript As String = "<script language='javascript'>" & _
"window.open('http://www.nu.nl', 'NU', " & _
"'width=200, height=200, menubar=yes, resizable=no')" &
_
"</script>"

Page.RegisterStartupScript("PopupScript", popupScript)
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim popupScript As String = "<script language='javascript'>" & _
"window.open('http://www.nu.nl', 'NU', " & _
"'width=200, height=200, menubar=yes,
resizable=no')" & _
"</script>"

Page.RegisterStartupScript("PopupScript", popupScript)
End Sub
End Class


 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      04-11-2005
That's because by Page_Load, button1 is already a valid button object, and
its event handler is hooked up.

You are discarding that object and creating a new one. But you are not
reattaching the event handler, which you must do via AddHandler. The
declaritive way of specifying the handler assumes you are letting the
asp.net runtime take care of instantiating the object, and not throwing away
what it does to do it yourself.

"gce" <(E-Mail Removed)> wrote in message
news:d3ecfn$lc8$(E-Mail Removed)1.ov.home.nl...
> Allthough button2 created with the designer works 100%. The button I
> created (inside the table) with dim button1 as new button doesn't give me
> a click event. Please help.
>
> Public Class WebForm8
>
> Inherits System.Web.UI.Page
>
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents Table1 As System.Web.UI.WebControls.Table
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents Button2 As System.Web.UI.WebControls.Button
>
> 'NOTE: The following placeholder declaration is required by the Web
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Dim rij1 As New TableRow
> Dim cel1 As New TableCell
> Dim cel2 As New TableCell
>
> Dim header As New TableHeaderCell
> header.RowSpan = 1
> header.ColumnSpan = 2
> header.Text = "test"
> header.Font.Bold = True
> header.HorizontalAlign = HorizontalAlign.Center
> header.VerticalAlign = VerticalAlign.Middle
>
> Dim headerrow As New TableRow
> headerrow.Cells.Add(header)
>
> Table1.Rows.Add(headerrow)
>
> Dim button1 As New Button
>
> button1.Text = "knop"
>
> cel1.Controls.Add(button1)
> cel2.Text = "cel2"
> rij1.Cells.Add(cel1)
> rij1.Cells.Add(cel2)
>
> Table1.Rows.Add(rij1)
>
>
>
>
> End Sub
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim popupScript As String = "<script language='javascript'>" & _
> "window.open('http://www.nu.nl', 'NU', " & _
> "'width=200, height=200, menubar=yes, resizable=no')" &
> _
> "</script>"
>
> Page.RegisterStartupScript("PopupScript", popupScript)
> End Sub
>
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim popupScript As String = "<script language='javascript'>" & _
> "window.open('http://www.nu.nl', 'NU', " & _
> "'width=200, height=200, menubar=yes,
> resizable=no')" & _
> "</script>"
>
> Page.RegisterStartupScript("PopupScript", popupScript)
> End Sub
> End Class
>
>



 
Reply With Quote
 
 
 
 
gce
Guest
Posts: n/a
 
      04-11-2005
Super ! That works great.

But now I want the same thing for a radiobutton and it doesn't work. My hope
was that when I check the radiobutton, the radiobutton1_checkedchanged would
be fired. Nope.

Dim radiobutton1 As New RadioButton
AddHandler radiobutton1.CheckedChanged, AddressOf
radiobutton1_CheckedChanged

Private Sub radiobutton1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles radiobutton1.CheckedChanged
Dim popupScript As String = "<script language='javascript'>" & _
"window.open('http://www.nu.nl', 'NU', " & _
"'width=200, height=200, menubar=yes,
resizable=no')" & _
"</script>"

Page.RegisterStartupScript("PopupScript", popupScript)
End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional array, one dim fix, one dim dynamic Florian Kaufmann C++ 1 04-28-2010 01:21 PM
System.arraycopy (2 dim array) and growth of 2 dim array Denis Palas Java 1 11-11-2006 09:22 AM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM



Advertisments