Events on my page

G

Guest

I'm trying to process the Onclick event of my page but it's never working. The button is dynamical added to the sites MainPanel.

If I click the button on the page the Page_Load Event() is processed during the postback but not the Sub Button_Click.

Where is my mistake

Thanks for hints and ideas
Steve

Here is my example code

Public Class WebForm
Inherits System.Web.UI.Pag

#Region " Web Form Designer Generated Code

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

End Su
Protected WithEvents MainPanel As System.Web.UI.WebControls.Pane

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

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

#End Regio

Protected WithEvents Button As New System.Web.UI.WebControls.Butto

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa

If Not IsPostBack The
Design_Page(
End I

End Su

Private Sub Design_Page(

Button.ID = "Button
Button.Style.Add("position", "absolute"
Button.Width = Unit.Pixel(30
Button.Height = Unit.Pixel(30

MainPanel.Controls.Add(Button

End Su

Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button.Clic
End Su

End Class
 
M

Michael

Just looking over it quickly, you may be running into a problem using
"button" as your button's id. .net can get confused when you start naming
your objects the same as its objects. I would avoid doing that for your
sanity :)

HTH,
--Michael

Steven ONeil said:
I'm trying to process the Onclick event of my page but it's never working.
The button is dynamical added to the sites MainPanel.
If I click the button on the page the Page_Load Event() is processed
during the postback but not the Sub Button_Click.
Where is my mistake?

Thanks for hints and ideas,
Steven

Here is my example code:

Public Class WebForm1
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 MainPanel As System.Web.UI.WebControls.Panel

'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

Protected WithEvents Button As New System.Web.UI.WebControls.Button

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 
G

Guest

Hi Michael,

I tried removing the ID but that does not help. After postback the Page_Load() event is processed but not the Button_Click() sub.....
 
M

Marina

You have to recreate the button every time the page loads.

Http is stateless - the page is recreated from scratch every time. If the
second time there is no button - there is no event to run for a button that
doesn't exist.

Steven ONeil said:
I'm trying to process the Onclick event of my page but it's never working.
The button is dynamical added to the sites MainPanel.
If I click the button on the page the Page_Load Event() is processed
during the postback but not the Sub Button_Click.
Where is my mistake?

Thanks for hints and ideas,
Steven

Here is my example code:

Public Class WebForm1
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 MainPanel As System.Web.UI.WebControls.Panel

'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

Protected WithEvents Button As New System.Web.UI.WebControls.Button

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 
M

Michael Ramey

Don't remove the ID, just rename it from "Button" to something like
"btnClick". You'll also have to change your handlers as well to update the
change.

Steven O'Neil said:
Hi Michael,

I tried removing the ID but that does not help. After postback the
Page_Load() event is processed but not the Button_Click() sub.....
 
B

bruce barker

you need to add the button (call your designpage) on postback also, for it
to be initialized. the button actually fires the onclick, so it need to be
initialized. also its a good practice to add dynamic controls at page init
rather than page load, so that they can retrieve their postback values.

try:

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
Design_Page()
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

-- bruce (sqlwork.com)


Steven ONeil said:
I'm trying to process the Onclick event of my page but it's never working.
The button is dynamical added to the sites MainPanel.
If I click the button on the page the Page_Load Event() is processed
during the postback but not the Sub Button_Click.
Where is my mistake?

Thanks for hints and ideas,
Steven

Here is my example code:

Public Class WebForm1
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 MainPanel As System.Web.UI.WebControls.Panel

'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

Protected WithEvents Button As New System.Web.UI.WebControls.Button

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top