|
-
Apr 30th, 2003, 11:04 AM
#1
Thread Starter
Lively Member
Add function to programatically created buttons?
I am adding a series of LinkButtons to a Panel in the code behide page and I have a Function called RemoveItem that I want it to run when clicked also in the code behind page. So I add the buttons like this:
Code:
fo i=0 to Session("ttlitems")
Dim b As New LinkButton
b.ID = "lbutton" & i
b.Text = "Remove"
b.ToolTip = "Remove this item"
b.Attributes.Add("onclick", "RemoveItem(" & i & ");")
panel1.controls.add(b)
next
And when I click the button I get an error. I can not setup button click events on the code behind because the buttons dont exist yet. So I'm kind of lost on this one.
"Find all you need in your mind if you take the time" -DT
-
Apr 30th, 2003, 03:30 PM
#2
Buttons is the worst thing to create programatically... why don't you try with the repeater control ? It's a lot easyer, and it works well with any control (ie buttons too)
If you don't know how to do it with a repeater control, just ask me.
-
May 1st, 2003, 07:56 AM
#3
Thread Starter
Lively Member
it really has to be done this way, I wish I could go the other route but this is what I have to do.
"Find all you need in your mind if you take the time" -DT
-
May 1st, 2003, 10:04 AM
#4
PowerPoster
Are you sure you can't use the repeater control? It sounds like it is the perfect situation for it.
-
May 4th, 2003, 11:13 PM
#5
Fanatic Member
guys, i have a whole bunch of programmatically created dropdownlist controls that works just fine right now, but i'm thinking i may benefit from the repeater control... any good reading on it?
-
May 5th, 2003, 06:00 AM
#6
Addicted Member
Originally posted by CVMichael
Buttons is the worst thing to create programatically...
Not with .NET is should say 
If you add the buttons, also add a handler to it using addhandler.
This is a easy and safe sollution.
-
May 5th, 2003, 06:34 AM
#7
Junior Member
b.Attributes.Add("onclick", "RemoveItem(" & i & ");")
will try to call RemoveItem function on click & will give you error if it is not there.
You need to add event handler for the button as
AddHandler Button1.Click, AddressOf Me.RemoveItem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|