473,789 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls.Butt on
Protected WithEvents tblDynamic As System.Web.UI.W ebControls.Tabl e
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
..
..
..
btnEditIdent = new System.Web.UI.W ebControls.Butt on
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 1933
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*******@nosp am.desotosystem s.com> ¼¶¼g©ó¶l¥ó·s»D: O4************* *@TK2MSFTNGP09. phx.gbl...
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.W ebControls.Butt on
Protected WithEvents tblDynamic As System.Web.UI.W ebControls.Tabl e
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.W ebControls.Butt on
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
"btnEditIde nt is underlined and the tooltips message I get when I hover over
the button is "'btnEditId ent is not a member of 'MyWeb.MyWebPag e'" (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.c om.hk> wrote in message
news:%2******** ********@TK2MSF TNGP12.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*******@nosp am.desotosystem s.com>

¼¶¼g©ó¶l¥ó·s»D: O4************* *@TK2MSFTNGP09. phx.gbl...
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.W ebControls.Butt on
Protected WithEvents tblDynamic As System.Web.UI.W ebControls.Tabl e
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.W ebControls.Butt on
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.Cl ick, 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*******@nosp am.desotosystem s.com> wrote in message
news:et******** ******@tk2msftn gp13.phx.gbl...
on the "AddHandler btnEditIdent, AddressOf MyButtonHandler " line, the
"btnEditIde nt is underlined and the tooltips message I get when I hover over the button is "'btnEditId ent is not a member of 'MyWeb.MyWebPag e'" (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.c om.hk> wrote in message
news:%2******** ********@TK2MSF TNGP12.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*******@nosp am.desotosystem s.com> ¼¶¼g©ó¶l¥ó·s»D: O4************* *@TK2MSFTNGP09. phx.gbl...
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.W ebControls.Butt on
Protected WithEvents tblDynamic As System.Web.UI.W ebControls.Tabl e
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
.
.
.
btnEditIdent = new System.Web.UI.W ebControls.Butt on
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
3564
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) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
1
7588
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
2234
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 the name of a common command (btn_Command) assigned to it's Command property. The creation of the table is done by a function called drawGeo. drawGeo is called during the initial Page_Load (!IsPostBack), but should be called by btn_Command on...
3
3986
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 step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
1
2296
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 find out which of the buttons triggered the postback *in the Page_Load* - here I have some code that needs to know which button was clicked so it will generate different output for the page.
3
1864
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 LiteralControl Dim lbtnCtrl As New LinkButton ltrCtrl.Text = "<br>" lbtnCtrl.Text = "WE: " & dtrCal(10).ToString lbtnCtrl.ToolTip = dtrCal(10).ToString & " these events" & dtrCal(1) lbtnCtrl.ID = "wecc" & i.ToString
2
3452
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 event to I "capture" in order to build the tree node menu in real time? right click on a tree node? or is it too late? just FYI: the menu is different for each node and is based on "real time"
4
2050
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 to DB and got the table into DataSet and also i hav placed one panel which contains image and label controls for dynamic image buttons i hav given the image URL from table only. and i hav written addHandler method to hanling events But for...
1
4918
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 another page in the same domain which also contains infragistics datagid populated with default data retrieved from Data Base. After creating the frame I am attaching it to the HTML DOM and show it as modal popup with OK and Cancel Button inside an...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.