Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How ASP.NET CommandName and CommandArgument values are stored?

Does anyone know where CommandName and CommandArgument properties of controls are stored? I am not interested in retrieving them, just to know more about ASP.NET internals and for future page size considerations. :)

I created a simple page containing 3 buttons having their commandArg and CommandName set as follows:

<asp:Button Text="Click1" runat="server" CommandArgument="1" CommandName="Delete" OnCommand="CommandExec" />
<asp:Button Text="Click2" runat="server" CommandArgument="2" CommandName="Save" OnCommand="CommandExec" />
<asp:Button Text="Click3" runat="server" CommandArgument="3" CommandName="Copy" OnCommand="CommandExec" />

changing CommandArgument or CommandName to a considerably large values do not affect ViewState content and size, so where these values are stored?

thanx

like image 379
Bakhshi Avatar asked May 08 '12 08:05

Bakhshi


People also ask

What is CommandName and CommandArgument in asp net?

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.

What is CommandArgument in asp net?

The CommandArgument property complements the CommandName property by allowing you to provide any additional information about the command to perform. For example, you can set the CommandName property to Sort and set the CommandArgument property to Ascending to specify a command to sort in ascending order.

What is the use of command name in ASP net?

When you have multiple Button controls on a Web page, use the CommandName property to specify or determine the command name associated with each Button control. You can set the CommandName property with any string that identifies the command to perform.


1 Answers

If you want to understand ASP.NET internals, I still think the best book is Developing ASP.NET Server Controls and Components by Nikhil Kothari and Vandana Datye. It's written for .NET 1.x, so a bit dated, but still covers the basic architecture really well.

In your example, the reason ViewState size is not affected is that ViewState is not being tracked during the Init phase when the markup is processed. Property values set to fixed values in the markup will be hardwired in the code generated when the ASP.NET page is compiled.

This MSDN article gives a good overview of ViewState.

You will see ViewState growing if you put the buttons in a data-bound control such as a repeater or GridView, and use data-binding syntax to have different values for the CommandArgument for each row.

like image 178
Joe Avatar answered Sep 16 '22 20:09

Joe