473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Events on my page

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
Nov 18 '05 #1
5 1183
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" <an*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
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

Nov 18 '05 #2
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.....
Nov 18 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
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

Nov 18 '05 #4
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" <an*******@discussions.microsoft.com> wrote in message
news:4A**********************************@microsof t.com...
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.....
Nov 18 '05 #5
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" <an*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
6
by: V | last post by:
I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the...
5
by: knocte | last post by:
Hello. I am a web developer very worried about "bloat code" and "languages mixture". So, since some time, I always try to avoid completely the use of javascript in XHTML/HTML files. This leads...
0
by: ChrisN | last post by:
Howdy, I'm writing a web application in VB.Net. I'm using C# for all of the dynamic content on the vb pages. I'm currently building a VB page that displays a table of pictures. The page calls...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
5
by: Paal Berggreen | last post by:
I am involved with development of a Portal solution using ASP.NET 2.0 and WebParts. The WebParts framework use the default personalization providers, and the personalization data thus ends up in...
1
by: Tina | last post by:
I'm a VB.Net developer learning C# so this is another newbie question.... (using 1.1) I posted a question about how to paste definitions for events in C# because in VB we use the vs.net left...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
3
by: =?Utf-8?B?VDhS?= | last post by:
Ok...I've been looking for an answer to this problem and can't seem to find one...Framework 1.1 mind you. I have a base class that inherits from UserControl. I have 5 and soon to be 12 user...
1
by: Scott M. | last post by:
How can I get Visual Studio 2008 Pro. to show me a list of the Page class's events (as I can get in VB .NET)? In the page designer, with the DOCUMENT selected in the Properties Window, there is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.