Events on my page

Discussion in 'ASP .Net' started by =?Utf-8?B?U3RldmVuIE9OZWls?=, Jan 28, 2004.

  1. 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
     
    =?Utf-8?B?U3RldmVuIE9OZWls?=, Jan 28, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?U3RldmVuIE9OZWls?=

    Michael Guest

    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" <> wrote in message
    news:...
    > 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
     
    Michael, Jan 28, 2004
    #2
    1. Advertising

  3. 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.....
     
    =?Utf-8?B?U3RldmVuIE8nTmVpbA==?=, Jan 28, 2004
    #3
  4. =?Utf-8?B?U3RldmVuIE9OZWls?=

    Marina Guest

    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" <> wrote in message
    news:...
    > 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
     
    Marina, Jan 28, 2004
    #4
  5. 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" <> wrote in message
    news:...
    > 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.....
     
    Michael Ramey, Jan 28, 2004
    #5
  6. =?Utf-8?B?U3RldmVuIE9OZWls?=

    bruce barker Guest

    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" <> wrote in message
    news:...
    > 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
     
    bruce barker, Jan 28, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shiv
    Replies:
    0
    Views:
    482
  2. Alvin Bruney
    Replies:
    1
    Views:
    727
  3. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    566
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  4. newbye
    Replies:
    0
    Views:
    582
    newbye
    Jul 6, 2006
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    375
    Chris
    Aug 30, 2005
Loading...

Share This Page