By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

Attaching client side code to an imagebutton rendered in a Reapeater

P: n/a
Hi:

I would like to attach client side code to an imagebutton that is rendered
in a Reapeater control. The client code will simply confirm if users wants
to continue with an operation. In this case it would be deleting a record.

For buttons that are placed on page at design time, I can use Add.Attributes
to achieve the above. However, controls in Reapeater are created at
runtime. How do I do this?

Thanks,
Charlie
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

you can access the button in Repeater's ItemCreated (or ItemDataBound) event
handler and specify the attribute there using Attributes property.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:eM****************@TK2MSFTNGP10.phx.gbl...
Hi:

I would like to attach client side code to an imagebutton that is rendered
in a Reapeater control. The client code will simply confirm if users wants to continue with an operation. In this case it would be deleting a record.
For buttons that are placed on page at design time, I can use Add.Attributes to achieve the above. However, controls in Reapeater are created at
runtime. How do I do this?

Thanks,
Charlie

Nov 18 '05 #2

P: n/a
I can get a reference to the button in ItemCreated using Controls[]
collection. However, when I assign the script Attribute, the event handler
is only assigned to first item in list when page is openened.

ImageButton btn = (ImageButton) e.Item.Controls[3];
btn.Attributes.Add("onclick", "return ImageButton1_onclick();");

How do I make it so all buttons rendered in page will have event handler
assigned?

Thanks,
Charlie

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:uT****************@TK2MSFTNGP09.phx.gbl...
Hi,

you can access the button in Repeater's ItemCreated (or ItemDataBound) event handler and specify the attribute there using Attributes property.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:eM****************@TK2MSFTNGP10.phx.gbl...
Hi:

I would like to attach client side code to an imagebutton that is rendered in a Reapeater control. The client code will simply confirm if users

wants
to continue with an operation. In this case it would be deleting a

record.

For buttons that are placed on page at design time, I can use

Add.Attributes
to achieve the above. However, controls in Reapeater are created at
runtime. How do I do this?

Thanks,
Charlie


Nov 18 '05 #3

P: n/a
Dear Charlie,
Thanks a ton for the sample code. It worked great for me.

Ashok Gupta

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.