Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Events on my page

Reply
Thread Tools

Events on my page

 
 
=?Utf-8?B?U3RldmVuIE9OZWls?=
Guest
Posts: n/a
 
      01-28-2004
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
 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      01-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3RldmVuIE8nTmVpbA==?=
Guest
Posts: n/a
 
      01-28-2004
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.....
 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      01-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> 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



 
Reply With Quote
 
Michael Ramey
Guest
Posts: n/a
 
      01-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.....


 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      01-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> 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



 
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
runtime events that generate other controls and events newbye ASP .Net 0 07-06-2006 06:27 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
order of events - dynamic checkbox events =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= ASP .Net 0 08-17-2005 10:36 PM
Re: passing variables between web page events & httpmodules events Alvin Bruney ASP .Net 1 11-24-2003 04:14 PM
Passing Variables between Web Page Events and HttpModule Events shiv ASP .Net 0 11-21-2003 04:29 PM



Advertisments