Problem adding dynamic LinkButton[] Array with event to a page

Problem adding dynamic LinkButton[] Array with event to a page

Post by marti » Wed, 10 Nov 2004 18:52:08


Hi,

i got a problem with adding a LinkButton array with one event for all
to a webpage. I read some posts about that here but some are not
answered and some have no solution for me.

1.
I added a LinkButton Array at the top of the page as member variable:

private LinkButton[] LinkButtonEdit;

2.
So that the events will be registered on every page load i created
a method private void InitializeLinkButtonEditEvents() wich is called
in the
standard Page_Load Method.

It contains the following code:
dbimages --> Create dbimages DataTable from some database rows.

LinkButtonEdit = new LinkButton[dbimages.Rows.Count]; int rowcount =
0;
foreach (DataRow row in dbimages.Rows )
{
LinkButtonEdit[rowcount] = new LinkButton();
LinkButtonEdit[rowcount].Text = "Edit";
LinkButtonEdit[rowcount].ID = "LinkButtonEdit_" +
row["img_id"].ToString();
LinkButtonEdit[rowcount].Click += new
System.EventHandler(this.LinnkButtonEdit_Click);

rowcount++;
}

3.
I add a table with the entries of the above datatable to the page
wich is showing some of the data and add the link button to each line

cellopt.Controls.Add( LinkButtonEdit[rowcount] );


4.
I added some Event Method

private void LinkButtonEdit_Click(object sender, System.EventArgs e)

with some debug output to a Label


The problem is: the event is not be fired - the page reloads but
i can't see my message. The link commands in the page-source looks
good.
What went wrong? Any suggestions? I have a working page like that
where the only difference is that i only got a char for the
buttonid's.


Thanks for some comment about that and best regards.

Martin Strojek
XXXX@XXXXX.COM
 
 
 

1. passing info from one dynamic array to another dynamic array in seperate asp pages

2. dynamic linkbuttons event not raising - newbie

Hi, I am creating a custom server control, and it dynamically creates lots
of LinkButtons, and then I try to subscribe to the click event doing this:
LinkButton link = new LinkButton();
link.Click +=new EventHandler(this.MyLinks_Click);

When I then click on the link, it never invokes MyLinks_Clicks... I guess
this happens because I don't create the linkbuttons neither on
CreateChildControls() nor OnInit(). I create them depending on some input
data and some properties.
All that MyLinks(...) does is set a property to a value, depending on the
linkbutton pressed, beacuse I need it when I render again my control.
Can someone give me a hint on how to solve this problem? Maybe instead of
subscribing to the event, I can catch the name of the linkbutton that caused
the PostBack or something.
Thanks

3. I know dynamic linkbuttons have to be added in oninit, but how does datagrid do it?

4. Dynamic Table with Dynamic LinkButtons

5. Event not firing from dynamically added linkbutton

6. Dynamically add linkbuttons and wire them to same event??

7. Adding LinkButton + click Event dynamically

8. Adding click event to linkbutton

9. Need help with order of page events and adding dynamic button controls.

10. How do I add a dynamic conection to a dynamic Webpart on the same event.

11. Missing LinkButton click events (viewstate problem)

12. LinkButton event handler and Page_Load problem

13. [PATCH 1/4] tracing, page-allocator: Add trace events for page allocation and page freeing

14. [PATCH 1/6] tracing, page-allocator: Add trace events for page allocation and page freeing

15. Gridview - Paging - Linkbutton - Problem