Asp.Net: Using the OnCommand Event with CommandArgument

by Pieter Brinkman 4. February 2009 08:53

When using a button, linkbutton or imagebutton with CommandArguments or CommandName you can use the OnCommand event instead of the OnClick event. Using the OnCommand Event you use less code to extract the CommandArgument and CommandName from the Event comparing to the OnClick event (because you don't need to cast the control).


Code example

The Aspx:

[code:html]

<asp:ImageButton ImageUrl="~/Includes/Images/delete_icon.gif" runat="server" ID="ibtDeleteClip" OnCommand="ibtDeleteClip_Command" CommandArgument='<%# Eval("ClipId") %>' />

[/code]

 

And the codebehind (C#):

[code:c#]


protected void ibtDeleteClip_Command(object sender, CommandEventArgs e)
{
   string commandArg = e.CommandArgument;
}

 

Tags: , , , , , ,

ASP.Net | Controls

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am Solution Architect for Sitecore in The Netherlands. My interests are mainly ASP.NET, MSSQL and Content Management Systems.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

RecentComments

Comment RSS

Most comments