Catching buttons in repeaters

F

Fraggle

*google wont let me post to
microsoft.public.dotnet.framework.aspnet.webcontrols so thats why i
posted here*

I have a repeater that i want to have an ImageButton and a linkbutton
in.

I catch the click in the repeater using OnItemCommand=" to run a sub.

I then cast to a button to check the CommandName=" and do what ever
the button is meant to be doing.

However when it comes to the cast i have to use

Dim command As String = CType(e.CommandSource, linkButton).CommandName

but when i added the imagebutton to the repeater and knocked the cast
back to

Dim command As String = CType(e.CommandSource, Button).CommandName

It fails; i get a "Specified cast is not valid" error.

<asp:button> <asp:Linkbutton> <asp:Imagebutton> all inherit from
System.Web.UI.WebControls.WebControl this seems like a fairly bad way
of going about things! I would have a general button class, and
specialise it :(

Whats even weirder (to me anyway) is linkbutton comes off
System.Web.UI.WebControls.Image

Anyway where do i go from here? do i just have to do lots of "try
catch" to sort out which TYPE of button the user clicked, then check
the command name then do the action?

Thanks for any ideas

Fragg
 

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,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top