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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With