Button event in DataList

D

David W. Simmonds

I have a Button in a DataList Footer. I add the click event like this:

void Item_DataBound(Object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Footer)
{
Button ctlSave = (Button)e.Item.FindControl("ctlSave");
ctlSave.Click += new EventHandler(ctlSave_Click);
}
}

It seems that the ctlSave_Click method is never called though. Am I doing
this right?
 
T

Teemu Keiski

Hi,

you'd need to wire this event in ItemCreated. I don't think the code ever
reaches Footer in ItemDataBound as footer isn't bindable item by default. In
ItemCreated Footer is always accessed (Footer item created), so that way it
should work.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


I have a Button in a DataList Footer. I add the click event like this:

void Item_DataBound(Object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Footer)
{
Button ctlSave = (Button)e.Item.FindControl("ctlSave");
ctlSave.Click += new EventHandler(ctlSave_Click);
}
}

It seems that the ctlSave_Click method is never called though. Am I doing
this right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top