what is the purpose of command name and command argument for a control example button? when should we go for this?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
Have a look at command name and command argument MSDN description.
With this you can pass in extra information when a button gets clicked. Notice that it's not the Click event that gets handled but the Command event.
The place where it's mostly used is in combination with grid control in ASP.NET where standard messages are passed in like Delete, Insert, ... and which get handled in the default eventhandlers of these controls.
For an overview of this, take a look here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx.
You can place a button on
asp:FormView
and subscribe to itsItemCommand
event.FormViewCommandEventArgs has properties
CommandName
andCommandArgument
which will be equal to your Button's if it will be pressed.CommandName is to identify which command you want to execute when a button is clicked, the event you need to handle is called Command (not Click), CommandArgument is the argument passed when you click that button, for example if you want to pass an ID.
CommandName
:(My emphasis)
CommandArgument
:...which you retrieve from the event object (for instance,
e
) ase.CommandArgument
.So for instance, you might have four buttons with the
CommandName
"DoSomething" but four differentCommandArguments
telling your "DoSomething" code what to do, or what to do it to. You might also have other buttons withCommandName
= "DoSomethingElse" that, well, do something else. :-)The Command event makes it easy to write a single method that handles the clicks of multiple buttons.