The name of the type of control

S

simon

I have button in asp:repeater control.

<asp:Button Runat=server ID=btnPList Text="..." CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"datumP")%>'></asp:Button>

In code behind I use the item-command event of data repeater:

Private Sub rprPlists_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles
rprPlists.ItemCommand

If e.CommandSource.GetType.Name.ToString() = "Button" Then
.......
end if

end sub

How can I do the same in C#?

I can't get the name of the command who fired the event.
The CommandSource.GetType.Name.ToString() doesn't work.

protected void rprPlists_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandSource.GetType.Name.ToString() == "Button"){
.....}
}
Any idea?
regards,S
 
G

Guest

This is how I did it:

In the aspx page, here's my button definition:

<asp:Button id="cmdRemoveMsg" runat="server" Text="Remove"
CommandArgument="<%# ((MyCustomClass)Container.DataItem).ID %>"
CommandName="Remove"></asp:Button>

In the code behind, first hook to the repeater's event:

this.rptrMessages.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHandler(this.rptrMessages_ItemCommand);

Finally, here's my handler:

private void rptrMessages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
string commandName = e.CommandName;
string commandArg = e.CommandArgument;
//Do stuff
}

Hope that helps.
 
S

simon

Hi Andy,

thank you for your answer.
I know you can do that by assigning CommandName="Remove", but I would like
to catch the tag name of the control,
so "button".

In VB, it works as you can see in my example.

Now I would like to achive the same with C# (also for some other purposes).
Do you know how?

Regards,Simon
 
G

Guest

Ah, I see. In that case, use this in the event handler:

e.CommandSource.GetType().Name
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top