OnItemCreated Event

G

Guest

I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the button.

The problem is that I can not find the control when I search for it in the event. I am guessing that internally it is assigning a unique ID to each of the buttons that the Datalist is creating and this is why I can not find the control with a "FindControl" method.

So how do I find the control? Here is the code I created...

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.FindControl("cmdPPIPEditDelete");
if (ctrl != null)
{
((Button)ctrl).Attributes["onclick"] = "return RecordDeleteConfirmation();";
}
}
 
A

avnrao

your code looks fine. if you are checking for OR operation (and not bitwise
or) in the code
you can replace | with || .
and make sure that your button id is correct.

hth,
Av.
 
G

Guest

It is the little things... I guess I was convinced that it would never find the control so I just missed that I had place the wrong name into the FindControl method.

Thanks

avnrao said:
your code looks fine. if you are checking for OR operation (and not bitwise
or) in the code
you can replace | with || .
and make sure that your button id is correct.

hth,
Av.

Jim Heavey said:
I have a DataList and I want to add some Javascript to a button in the
Datalist. I am guessing that I will use the "OnItemCreated" event to find
my control and then load the java script to the button.

The problem is that I can not find the control when I search for it in the
event. I am guessing that internally it is assigning a unique ID to each
of the buttons that the Datalist is creating and this is why I can not
find the control with a "FindControl" method.

So how do I find the control? Here is the code I created...

if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.FindControl("cmdPPIPEditDelete");
if (ctrl != null)
{
((Button)ctrl).Attributes["onclick"] = "return
RecordDeleteConfirmation();";
}
}
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top