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

generated buttons

using this usercontrol
- http://www.denisbauer.com/ASPNETCont...aceholder.aspx -
I manage to create several inputfields and buttons, depending on what user
needs.
works fine

However, I do not find much useable help on recreating eventhandlers for
dynamic generated buttons. All I seem to find is when you know in advance how
much buttons will be created, which unfortunately is not the case in my
application

anyone an idea ?

Nov 19 '05 #1
3 1145
Salut Benoit,

If you are creating buttons dynamically, you need to use Addhandler to
create the event and tell it the name of the routine that handles the event.

AddHandler btnBtn.Click, AddressOf displayit

I've pasted in some code below that creates buttons in a loop and adds
handlers for each.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Dim ee As New EventArgs
Private Sub Page_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim txtBx As TextBox
Dim btnBtn As Button
Dim lblLbl As Label
Dim litLiteral As Literal
Dim intCounter As Integer

For intCounter = 1 To 5
btnBtn = New Button
btnBtn.Text = "Button" & intCounter.ToString
lblLbl = New Label
lblLbl.Text = "Label" & intCounter.ToString
litLiteral = New Literal
litLiteral.Text = "<br>"
PlaceHolder1.Controls.Add(litLiteral)
PlaceHolder1.Controls.Add(lblLbl)
PlaceHolder1.Controls.Add(litLiteral)
ee.Equals(lblLbl)
AddHandler btnBtn.Click, AddressOf displayit
PlaceHolder1.Controls.Add(btnBtn)
PlaceHolder1.Controls.Add(litLiteral)
Next

End Sub
Public Sub displayit(ByVal s As Object, ByVal e As EventArgs)
Dim btn As Button
btn = s

Label1.Text = btn.ClientID & _
": Dynamically Added Link Button is Clicked"
End Sub

<form id="Form1" method="post" runat="server">
<p>
<asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>
</form>

"benoit" <be****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
using this usercontrol
-
http://www.denisbauer.com/ASPNETCont...aceholder.aspx -
I manage to create several inputfields and buttons, depending on what user
needs.
works fine

However, I do not find much useable help on recreating eventhandlers for
dynamic generated buttons. All I seem to find is when you know in advance
how
much buttons will be created, which unfortunately is not the case in my
application

anyone an idea ?


Nov 19 '05 #2
JV
If you drop a button on a form, add a CLICK handler then look at your code,
you will be able to see exactly how it's done. You'll just have to do
likewise in your code for dynamically created buttons. Look for a section
in your code as follows:

#region Web Form Designer generated code

You will find a function called InitializeComponent() which has some code
that sets up your event handler. For example, for your PAGE_LOAD event, you
will see something like:
this.Load += new System.EventHandler(this.Page_Load);

That is how you tell the control to call your function.

"benoit" <be****@discussions.microsoft.com>
using this usercontrol
-
http://www.denisbauer.com/ASPNETCont...aceholder.aspx -
I manage to create several inputfields and buttons, depending on what user
needs.
works fine

However, I do not find much useable help on recreating eventhandlers for
dynamic generated buttons. All I seem to find is when you know in advance
how
much buttons will be created, which unfortunately is not the case in my
application

anyone an idea ?

Nov 19 '05 #3
Just in case people still have issues... I was doing a similar thing where I
built a treeview hierarchy with CheckBoxes dynamically. When I added the
event handlers, they did not fire UNTIL i added the handlers BEFORE I added
the control to the parent!!!

It seems that when you add the control to the parent's collection, event
handlers must have already been setup on the dynamic control.

"Ken Cox [Microsoft MVP]" wrote:
Salut Benoit,

If you are creating buttons dynamically, you need to use Addhandler to
create the event and tell it the name of the routine that handles the event.

AddHandler btnBtn.Click, AddressOf displayit

I've pasted in some code below that creates buttons in a loop and adds
handlers for each.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Dim ee As New EventArgs
Private Sub Page_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim txtBx As TextBox
Dim btnBtn As Button
Dim lblLbl As Label
Dim litLiteral As Literal
Dim intCounter As Integer

For intCounter = 1 To 5
btnBtn = New Button
btnBtn.Text = "Button" & intCounter.ToString
lblLbl = New Label
lblLbl.Text = "Label" & intCounter.ToString
litLiteral = New Literal
litLiteral.Text = "<br>"
PlaceHolder1.Controls.Add(litLiteral)
PlaceHolder1.Controls.Add(lblLbl)
PlaceHolder1.Controls.Add(litLiteral)
ee.Equals(lblLbl)
AddHandler btnBtn.Click, AddressOf displayit
PlaceHolder1.Controls.Add(btnBtn)
PlaceHolder1.Controls.Add(litLiteral)
Next

End Sub
Public Sub displayit(ByVal s As Object, ByVal e As EventArgs)
Dim btn As Button
btn = s

Label1.Text = btn.ClientID & _
": Dynamically Added Link Button is Clicked"
End Sub

<form id="Form1" method="post" runat="server">
<p>
<asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>
</form>

"benoit" <be****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
using this usercontrol
-
http://www.denisbauer.com/ASPNETCont...aceholder.aspx -
I manage to create several inputfields and buttons, depending on what user
needs.
works fine

However, I do not find much useable help on recreating eventhandlers for
dynamic generated buttons. All I seem to find is when you know in advance
how
much buttons will be created, which unfortunately is not the case in my
application

anyone an idea ?


Nov 19 '05 #4

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

Similar topics

9
by: Marek Mand | last post by:
How to use generated keyboard events? What I am trying here to do is in onkeyup event handler http://www.hot.ee/idaliiga/braggart/createEventTest.htm generate a (shift)TAB keydown so the...
4
by: KvS | last post by:
Hi all, I'm pretty new to (wx)Python so plz. don't shoot me if I've missed something obvious ;). I have a panel inside a frame, on which a Button and a StaticText is placed: self.panel =...
4
by: JezB | last post by:
I am dynamically creating WebControls and creating them on my page. Some of these are buttons, and I attach events to these buttons. The problem is these force a post-back, so I must regenerate all...
5
by: benoit | last post by:
I heve this webform with a checkboxlist and a button. Based on which checkboxes are checked, several textboxes and Buttons are generated. When I click one of these buttons, the page goes in...
2
by: ghadley_00 | last post by:
Hi, I have a database with a main table and a lookup table of customers, and reports for each of the customers listing each transaction they have listed. I have a form that has buttons for...
5
by: mk | last post by:
Greetings all - im new to this newsgroup so pls dont flame me :p I need some help! Please view the html below in a browser. Or goto this url -http://firebrain.co.uk/java-problem.htm (Assuming...
2
by: Ian :\) | last post by:
Hi Just learning JavaScript and I'm trying to reference radio buttons generated by php, the relevant lines are: <td width="9%" align="center" class="bg-tb-td"><input name="editArticle"...
4
by: anokun7 | last post by:
Hi, We have an application that generates html code through a GUI... The html fields (like radio, checkbox etc..) generated are all inside table/tr/td. And none of the fields are assigned any id....
18
by: bning | last post by:
Hmm this forum really doesn't give you long enough to type in your question before logging you out.. well here goes my second attempt: I'm trying to teach myself javascript with dom scripting and...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.