473,322 Members | 1,526 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,322 software developers and data experts.

dynamic button creation with event handling?

How can I dynamically create buttons and wire them to an event handler? I
have seen how I can add buttons to an event handler that are pre-created as
part of the codebehind using AddHandler, but I can't use AddHandler with a
button that is created locally, nor can I seem to create multiple button
objects and add them to the page using a button object that exists outside
the procedure I am using.... thus:

Protected WithEvents btnEditIdent As System.Web.UI.WebControls.Button
Protected WithEvents tblDynamic As System.Web.UI.WebControls.Table
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
..
..
..
btnEditIdent = new System.Web.UI.WebControls.Button
btnEditIdent.id="btn" & strSomeUniqueID
dim tc as TableCell
AddHandler btnEditIdent, AddressOf MyButtonHandler
tc.Controls.Add(btnEditIdent)
..
..
..
End Sub
Seems like the above should work. But it generates an error.
Any ideas?

Thanks
Peter R. Vermilye
Nov 19 '05 #1
3 1908
Seems the code is okay... so what is the error message?

Also make sure you're placing the control inside table within the <form
runat="server"> tag.

"Peter Vermilye" <pv*******@nospam.desotosystems.com> ¼¶¼g©ó¶l¥ó·s»D:O4**************@TK2MSFTNGP09.phx.g bl...
How can I dynamically create buttons and wire them to an event handler? I
have seen how I can add buttons to an event handler that are pre-created
as
part of the codebehind using AddHandler, but I can't use AddHandler with a
button that is created locally, nor can I seem to create multiple button
objects and add them to the page using a button object that exists outside
the procedure I am using.... thus:

Protected WithEvents btnEditIdent As System.Web.UI.WebControls.Button
Protected WithEvents tblDynamic As System.Web.UI.WebControls.Table
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.WebControls.Button
btnEditIdent.id="btn" & strSomeUniqueID
dim tc as TableCell
AddHandler btnEditIdent, AddressOf MyButtonHandler
tc.Controls.Add(btnEditIdent)
.
.
.
End Sub
Seems like the above should work. But it generates an error.
Any ideas?

Thanks
Peter R. Vermilye

Nov 19 '05 #2
on the "AddHandler btnEditIdent, AddressOf MyButtonHandler" line, the
"btnEditIdent is underlined and the tooltips message I get when I hover over
the button is "'btnEditIdent is not a member of 'MyWeb.MyWebPage'" (where
MyWeb is the name of the application and MyWebPage is the name of the class
for that particular web page.

Yes, the table is inside the <form runat="server"> tag.

Point of clarification: The button is not defined on the web page itself
(in the MyWebPage.aspx file). Should it be? With anything special about it
since I don't intend to use that button but will be using multiple instances
of said button as determined by my code

Thanks for your time in looking at this.

Peter

"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Seems the code is okay... so what is the error message?

Also make sure you're placing the control inside table within the <form
runat="server"> tag.

"Peter Vermilye" <pv*******@nospam.desotosystems.com>

¼¶¼g©ó¶l¥ó·s»D:O4**************@TK2MSFTNGP09.phx.g bl...
How can I dynamically create buttons and wire them to an event handler? I have seen how I can add buttons to an event handler that are pre-created
as
part of the codebehind using AddHandler, but I can't use AddHandler with a button that is created locally, nor can I seem to create multiple button
objects and add them to the page using a button object that exists outside the procedure I am using.... thus:

Protected WithEvents btnEditIdent As System.Web.UI.WebControls.Button
Protected WithEvents tblDynamic As System.Web.UI.WebControls.Table
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.WebControls.Button
btnEditIdent.id="btn" & strSomeUniqueID
dim tc as TableCell
AddHandler btnEditIdent, AddressOf MyButtonHandler
tc.Controls.Add(btnEditIdent)
.
.
.
End Sub
Seems like the above should work. But it generates an error.
Any ideas?

Thanks
Peter R. Vermilye


Nov 19 '05 #3
I just changed the AddHandler line to read as follows:

AddHandler btnEditIdent.Click, AddressOf MyButtonHandler

the underline went away after that (which NOW makes sense...i wasn't
identifying what event to handle. But in the tutorials I'd looked at, they
never referenced the event itself....I'm going to go test and see if that's
where my stupidity was.

Thanks for your input!

Peter

"Peter Vermilye" <pv*******@nospam.desotosystems.com> wrote in message
news:et**************@tk2msftngp13.phx.gbl...
on the "AddHandler btnEditIdent, AddressOf MyButtonHandler" line, the
"btnEditIdent is underlined and the tooltips message I get when I hover over the button is "'btnEditIdent is not a member of 'MyWeb.MyWebPage'" (where
MyWeb is the name of the application and MyWebPage is the name of the class for that particular web page.

Yes, the table is inside the <form runat="server"> tag.

Point of clarification: The button is not defined on the web page itself
(in the MyWebPage.aspx file). Should it be? With anything special about it since I don't intend to use that button but will be using multiple instances of said button as determined by my code

Thanks for your time in looking at this.

Peter

"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Seems the code is okay... so what is the error message?

Also make sure you're placing the control inside table within the <form
runat="server"> tag.

"Peter Vermilye" <pv*******@nospam.desotosystems.com> ¼¶¼g©ó¶l¥ó·s»D:O4**************@TK2MSFTNGP09.phx.g bl...
How can I dynamically create buttons and wire them to an event handler? I
have seen how I can add buttons to an event handler that are
pre-created as
part of the codebehind using AddHandler, but I can't use AddHandler with
a button that is created locally, nor can I seem to create multiple
button objects and add them to the page using a button object that exists

outside the procedure I am using.... thus:

Protected WithEvents btnEditIdent As System.Web.UI.WebControls.Button
Protected WithEvents tblDynamic As System.Web.UI.WebControls.Table
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.WebControls.Button
btnEditIdent.id="btn" & strSomeUniqueID
dim tc as TableCell
AddHandler btnEditIdent, AddressOf MyButtonHandler
tc.Controls.Add(btnEditIdent)
.
.
.
End Sub
Seems like the above should work. But it generates an error.
Any ideas?

Thanks
Peter R. Vermilye



Nov 19 '05 #4

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Klom Dark | last post by:
I've got a weird problem going on - I've got a table of dynamically created buttons. Each button has the X/Y value of the buttons position in the table assigned to it's CommandArgument property and...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
4
by: vamshiv | last post by:
hi...im working on asp.net with VB i have created a database which hav fields id,name,image path in web form i hav written code for creation of image buttons dynamically i hav connected the form...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.