How to reference EventArgs e?

C

clintonG

When I use e. in an event handler all Intellisense wants to show me is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even though they
are properties documentation at MSDN shows they can be referenced (get) the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get how to
use an [OnCommand | OnClick] method with CommandName, and CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 
G

Guest

I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)
 
C

clintonG

Good point about the CommandEventArgs e parameter but the MSDN document
shows the control using an OnCommand="CommandBtn_Click" attribute pair
which is inconsistent with what your comments suggest [would | should]
coincide with one another, e.g. OnCommand="CommandBtn_Command or
OnClick="CommandBtn_Click" wouldn't you think?

<%= Clinton





Dabbler said:
I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)

clintonG said:
When I use e. in an event handler all Intellisense wants to show me is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even though
they
are properties documentation at MSDN shows they can be referenced (get)
the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get how to
use an [OnCommand | OnClick] method with CommandName, and CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 
G

Guest

the attribute OnCommand can be assigned any arbitrary value, e.g.
OnCommand="foo" as long as there is a corresponding method in the codebehind
file with that name e.g.
protected void foo(object sender, CommandEventArgs e){...

The choice of CommandBtn_Click for a value in the docs is a tad confusing
because of the "Click" in the string, but it's just a string.

clintonG said:
Good point about the CommandEventArgs e parameter but the MSDN document
shows the control using an OnCommand="CommandBtn_Click" attribute pair
which is inconsistent with what your comments suggest [would | should]
coincide with one another, e.g. OnCommand="CommandBtn_Command or
OnClick="CommandBtn_Click" wouldn't you think?

<%= Clinton





Dabbler said:
I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)

clintonG said:
When I use e. in an event handler all Intellisense wants to show me is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even though
they
are properties documentation at MSDN shows they can be referenced (get)
the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get how to
use an [OnCommand | OnClick] method with CommandName, and CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 
C

clintonG

After last reply I used the CommandEventArgs e as the parameter for the
click event handler as you reminded and I see what you mean in your last
reply about the name value of the attribute being an arbitrary string.

When the OnCommand attribute is used within a corresponding control
declaration we must use CommandEventArgs e as the parameter in the event
handler but the event handler type can be either <String>_Click or
<String>_Command.

Now, why would we want to choose _Click or _Command? It seems we want to use
_Command when needing to bubble properties up to another event handler but
again I'm still shady on that too. Going to sleep on it tonight. I had an in
patient procedure today (epidural) and the narcotics are all worn out and
I'm really exhausted. Thanks for helping me think through this Dabbler...

<%= Clinton




Dabbler said:
the attribute OnCommand can be assigned any arbitrary value, e.g.
OnCommand="foo" as long as there is a corresponding method in the
codebehind
file with that name e.g.
protected void foo(object sender, CommandEventArgs e){...

The choice of CommandBtn_Click for a value in the docs is a tad confusing
because of the "Click" in the string, but it's just a string.

clintonG said:
Good point about the CommandEventArgs e parameter but the MSDN document
shows the control using an OnCommand="CommandBtn_Click" attribute pair
which is inconsistent with what your comments suggest [would | should]
coincide with one another, e.g. OnCommand="CommandBtn_Command or
OnClick="CommandBtn_Click" wouldn't you think?

<%= Clinton





Dabbler said:
I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic
event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)

:

When I use e. in an event handler all Intellisense wants to show me
is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even though
they
are properties documentation at MSDN shows they can be referenced
(get)
the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get how
to
use an [OnCommand | OnClick] method with CommandName, and
CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 
G

Guest

I think you are missing my point, the name of the event handler is truly
arbitary, it could be <string>_Click, <string>_Command or <string>_ummagumma.
The attribute name determines the event type, not the attribute value, e.g.
OnCommand or OnClick, not <string>_Command or <string>_anything.

Hope you feel better in the morning ;)


clintonG said:
After last reply I used the CommandEventArgs e as the parameter for the
click event handler as you reminded and I see what you mean in your last
reply about the name value of the attribute being an arbitrary string.

When the OnCommand attribute is used within a corresponding control
declaration we must use CommandEventArgs e as the parameter in the event
handler but the event handler type can be either <String>_Click or
<String>_Command.

Now, why would we want to choose _Click or _Command? It seems we want to use
_Command when needing to bubble properties up to another event handler but
again I'm still shady on that too. Going to sleep on it tonight. I had an in
patient procedure today (epidural) and the narcotics are all worn out and
I'm really exhausted. Thanks for helping me think through this Dabbler...

<%= Clinton




Dabbler said:
the attribute OnCommand can be assigned any arbitrary value, e.g.
OnCommand="foo" as long as there is a corresponding method in the
codebehind
file with that name e.g.
protected void foo(object sender, CommandEventArgs e){...

The choice of CommandBtn_Click for a value in the docs is a tad confusing
because of the "Click" in the string, but it's just a string.

clintonG said:
Good point about the CommandEventArgs e parameter but the MSDN document
shows the control using an OnCommand="CommandBtn_Click" attribute pair
which is inconsistent with what your comments suggest [would | should]
coincide with one another, e.g. OnCommand="CommandBtn_Command or
OnClick="CommandBtn_Click" wouldn't you think?

<%= Clinton





I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic
event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)

:

When I use e. in an event handler all Intellisense wants to show me
is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even though
they
are properties documentation at MSDN shows they can be referenced
(get)
the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get how
to
use an [OnCommand | OnClick] method with CommandName, and
CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 
C

clintonG

I feel great this morning thanks.

I probably didn't convey it clearly but I understood you. I still need to
really understand the scope of using the OnCommand attribute. Command to
what for example? BTW, its a quibble but I wrote <String>_EventName to
follow the consensus naming convention. An event would not ordinarily be
named using camel case. Are you a maverick ? ;-)

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

Dabbler said:
I think you are missing my point, the name of the event handler is truly
arbitary, it could be <string>_Click, <string>_Command or
<string>_ummagumma.
The attribute name determines the event type, not the attribute value,
e.g.
OnCommand or OnClick, not <string>_Command or <string>_anything.

Hope you feel better in the morning ;)


clintonG said:
After last reply I used the CommandEventArgs e as the parameter for the
click event handler as you reminded and I see what you mean in your last
reply about the name value of the attribute being an arbitrary string.

When the OnCommand attribute is used within a corresponding control
declaration we must use CommandEventArgs e as the parameter in the event
handler but the event handler type can be either <String>_Click or
<String>_Command.

Now, why would we want to choose _Click or _Command? It seems we want to
use
_Command when needing to bubble properties up to another event handler
but
again I'm still shady on that too. Going to sleep on it tonight. I had an
in
patient procedure today (epidural) and the narcotics are all worn out and
I'm really exhausted. Thanks for helping me think through this Dabbler...

<%= Clinton




Dabbler said:
the attribute OnCommand can be assigned any arbitrary value, e.g.
OnCommand="foo" as long as there is a corresponding method in the
codebehind
file with that name e.g.
protected void foo(object sender, CommandEventArgs e){...

The choice of CommandBtn_Click for a value in the docs is a tad
confusing
because of the "Click" in the string, but it's just a string.

:

Good point about the CommandEventArgs e parameter but the MSDN
document
shows the control using an OnCommand="CommandBtn_Click" attribute
pair
which is inconsistent with what your comments suggest [would | should]
coincide with one another, e.g. OnCommand="CommandBtn_Command or
OnClick="CommandBtn_Click" wouldn't you think?

<%= Clinton





I'm no expert here but...
Intellisense is working, EventArgs is a generic base event that
knows
nothing about commands.

OnClick="Button_Click"
corresponds to:
protected void Button_Click(object sender, EventArgs e){.. generic
event

whereas

OnCommand="Button_Command"
corresponds to :
protected void Button_Command(object sender, CommandEventArgs e){
switch ( e.CommandName ) {
case "Cancel":
// do stuff
Response.Redirect( "RegistrantList.aspx" );
break;
}
}

that's my foggy interpretation of things at hand ;)

:

When I use e. in an event handler all Intellisense wants to show me
is:

// Event handler
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// can only 'see" these properties of e
e. [Equals | GetHashCode | GetType | ToString ]
// can only 'see" these properties of sender
sender.[Equals | GetHashCode | GetType | ToString ]
}

// BuildNewFileButton control declaration
<asp:Button ID="BuildNewFileButton"
OnCommand="BuildNewFileButton_Click"
CommandName="FileStructure"
CommandArgument="NoExtensions"
Text="Build New File"
runat="server"/>

The control declares a CommandName and CommandArgument and even
though
they
are properties documentation at MSDN shows they can be referenced
(get)
the
CommandArgument property through e as follows...

// Get value of CommandArgument
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
if(e.CommandArgument == "NoExtensions")
// do something...
}

I've read the documents at MSDN [1,2] but I really still don't get
how
to
use an [OnCommand | OnClick] method with CommandName, and
CommandArgument
properties...

....What am I failing to understand here?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

[1]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
[2]
http://msdn2.microsoft.com/en-us/li...ontrols.commandeventargs.commandargument.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top