473,473 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A Matter of Design: OnCommand or OnClick Event Handler?

A Matter of Design: OnCommand or OnClick Event Handler?

Attributing a control using OnCommand supports the use of other attibutes
such as CommandName and CommandArgument. AFIK OnClick does not.
Where it matters when using OnCommand for example is the value of the
CommandArgument seems to be easier to use to indicate some behavior in that
can be handled in the event handler that would have to use a value from some
other control such as the state of a radio button to indicate behavior a
click event should handle.

Is it a good practice to use OnCommand this way?
I really don't understand the intended use of OnCommand yet. Command what
for example?

It seems like a good idea to use the OnCommand CommandArgument and I sure
like the idea of accessing properties using e which is supported in
IntelliSense when it means one or less controls need to be used to indicate
the context of some desired behavior as following examples imply...

// Command event handler: succint, terse and readable and context relevant
protected void BuildNewFileButton_Command(Object sender, CommandEventArgs e)
{
if(e.CommandArgument == "NoExtensions")
Response.Redirect("Somewhere.aspx");
else
Response.Redirect("~/HomePage.aspx");
}

// Click event handler: verbose
protected void BuildNewFileButton_Click(Object sender, EventArgs e)
{
// PITA when using MasterPages
Button buildNewFileRadioButton =
(Button)Master.FindControl("...").FindControl("... ").FindControl("...");

if(buildNewFileBuildRadioButton == "Selected")
Response.Redirect("Somewhere.aspx");
else
Response.Redirect("~/HomePage.aspx");
}

Your comments?
Aug 30 '06 #1
0 1118

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: annon | last post by:
I've noticed that some problems come up frequently that are of importance in writing web pages, because they're pretty fundamental points. For general reference, here are some collected...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
7
by: Ramsi | last post by:
My development environment is ASP.Net 1.1. Clicked event of a button has lengthy procedure it will take 2 to 4 seconds to process the data. My question is, 1.. If the user clicks the button...
2
by: Matthew MacDonald | last post by:
Hi all, I am adding controls to a table dynamically. I have a list that I am putting into the session to keep track of them on postback. What I need to know though, is how to add the oncommand...
2
by: needin4mation | last post by:
I have a single button. I want to change it's OnCommand. One moment it may be Update, the next it may be New, etc. I found btnMyButton.Command, but I cannot get it to work. The event never...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
17
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.