Results 1 to 7 of 7

Thread: Add function to programatically created buttons?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Worcester, MA
    Posts
    77

    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

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Worcester, MA
    Posts
    77
    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

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Are you sure you can't use the repeater control? It sounds like it is the perfect situation for it.

  5. #5
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    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?

  6. #6
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    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.

  7. #7
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    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
    vijay pahuja
    mumbai

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width