How do I create a Linkbutton and Event Hander on the fly ?

  • Thread starter Thread starter James Norton-Jones
  • Start date Start date
J

James Norton-Jones

Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly. However I
haven't managed to connect the to an Event Handler.

Regards

James.
 
Good question
I would love to know the answer to this too.

The thing is that I am not sure if dynamically created controls can be
referenced properly in the code behind page. What i mean is if you
dynamically created something like System.Web.UI.WebControls.TextBox
text01; , I don't think you'll be able to get the compiler to compile when
you try to reference text01 in your static code, similarly eventhandlers are
attached to any particular static control on your page. So i am not sure
what you are trying to do is possible. although it would make more sense
that it should be possible.

Call in the experts....

Cheers

J
 
Have a look at my previous posting 'Programatically creating Linkbuttons but
....'
Which dynamically create the controls but does not handle any events.
 
As it turns out this is quite easy ie:

lbButton = New LinkButton

lbButton.Text = "Edit"

lbButton.CommandName = lbButton.Text

lbButton.CommandArgument = rs.Fields("Id").Value

AddHandler lbButton.Command, AddressOf Me.LinkButton_Command
 
Back
Top