Event processing

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 on the button the PageLoad Event is processed but no event method called. How can I fix?

Thanks a lot
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

If Not IsPostBack Then
Design_Page()
End If


End Sub

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 Sub


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

End Class
 
H

Hans Kesting

see inline

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 on the
button the PageLoad Event is processed but no event method called. How can I
fix?
Thanks a lot
Steven

Here is my example code:

Public Class WebForm1
Inherits System.Web.UI.Page
[snip]

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
If Not IsPostBack Then
Design_Page()
End If

You need to call "Design_Page()" always, not just the first time this page
is rendered.
Now the button will not be present the second time the page is processed, so
server side
code can not be executed for it.
 
G

Guest

Thanks for your reply, Hans. It's try that the button is not there anymore if I click the button and the postback is done
My problem is that if the button is clicked and the Page_Load event is processed again it's not jumping from Page_Load() to Button_Click ! But that is what i expected
More ideas?

Steven
 

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

Top