Results 1 to 8 of 8

Thread: Command Name Property + Button

  1. #1
    Lively Member
    Join Date
    Apr 09
    Posts
    116

    Command Name Property + Button

    Code:
    protected void Button1_Command(object sender, CommandEventArgs e)
        {
    
        }
    Code:
    protected void Button1_Click(object sender, EventArgs e)
        {
    
        }
    Whats the difference between above two lines of code???

    I read that you can write all the button click events code in one button command event??
    But Even we can assign button click event to more than one Button.???

    When we use Command Name event????

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,731

    Re: Command Name Property + Button

    Hey,

    The difference between the two is that one accepts a parameter of EventsArgs, and the other contains CommandEventArgs. These are two very different things, and they will provide very different properties.

    You can easily create one event handler, that handles the click event of multiple buttons.

    You would do this as follows:

    1) Create the event handler:

    Code:
    protected void CommonButtonClick(object sender, EventArgs e)
        {
    
        }
    2) Hook up the various button click events to use this event.

    You can see how this can be achieved here:

    http://www.vbforums.com/showthread.p...95#post3643595

    In post #7.

    Hope that helps!!

    Gary

  3. #3
    Frenzied Member brin351's Avatar
    Join Date
    Mar 07
    Location
    Land Down Under
    Posts
    1,256

    Re: Command Name Property + Button

    Hey Gary, I read your link and am amazed that after quite a few years using VS I have never clicked the "yellow lighting bolt" to view control events in the properties window. How didn't I know it was there...... I look at that window countless hours a week.

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,731

    Re: Command Name Property + Button

    Ha ha, it is one of those features that is quite often overlooked. Especially if you come from a VB background. In VB, you have the option of selecting events directly in the code view, but you can't do this in C#. Although the yellow bolt also exists in VB.Net land, it is the only interface that C# has.

    Gary

  5. #5
    Frenzied Member brin351's Avatar
    Join Date
    Mar 07
    Location
    Land Down Under
    Posts
    1,256

    Re: Command Name Property + Button

    Ah VB land can become a little too comfortable after a while. Thanks for your insight.

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,731

    Re: Command Name Property + Button

    I guess I had the benefit of starting in VB, and then transferring over to C# in my most recent job, so I have to converse in both languages, so I have picked up a few things along the way.

    Gary

  7. #7
    Lively Member
    Join Date
    Apr 09
    Posts
    116

    Re: Command Name Property + Button

    hi Gep13, I know that we bind multiple buttons to a single event handler,we can also bind the multiple buttons to a single command event.Can you give me example where command event is used? I dont think so it of any use?

  8. #8
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,731

    Re: Command Name Property + Button

    Hey,

    As per the documentation:

    http://msdn.microsoft.com/en-us/libr...n.command.aspx

    You would use the Command event handler, when there is a CommandName associated with the button.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •