473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Handling aspButton Click events

I am writing my first Web application, and have a question regarding
asp Buttons of Submit and Command Type.

I have a WebForm with a Command Button on it that I am creating in the
Page_Load :

....

// ADD Button
Button cmdAdd = new Button();
cmdAdd.Text = "Add";
cmdAdd.CommandName = "Add";
cmdAdd.CommandArgument="AddLine";

cmdAdd.Command += new CommandEventHandler ( HandleButtonPressed );
....
When the button is pressed I want it to be handled in a delegate like
this :
....
private void HandleButtonPressed ( object sender, CommandEventArgs e)
{
// handle stuff here - I add a row to a Table
}
....
However, the first time I press the button this method is called as I
want, and the next time the Button seems to do a Submit without
calling my event handler. Is it possible to combine the two, so that I
press the button, perform my action in the Command Event Handler and
refresh my WebForm with the changes in my action?
Nov 16 '05 #1
1 1224
Hi Aidan:

For your first application you should probably take a look at
declaring controls in the ASPX with markup like:

<asp:Button runat="server" id="cmdAdd"/>

You can add controls to the page with code as you are trying but there
are additional complications in that approach. Do you have a tuturial
to work through?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 28 Oct 2004 07:51:55 -0700, at*****@yahoo.com (AidanT) wrote:
I am writing my first Web application, and have a question regarding
asp Buttons of Submit and Command Type.

I have a WebForm with a Command Button on it that I am creating in the
Page_Load :

...

// ADD Button
Button cmdAdd = new Button();
cmdAdd.Text = "Add";
cmdAdd.CommandName = "Add";
cmdAdd.CommandArgument="AddLine";

cmdAdd.Command += new CommandEventHandler ( HandleButtonPressed );
...
When the button is pressed I want it to be handled in a delegate like
this :
...
private void HandleButtonPressed ( object sender, CommandEventArgs e)
{
// handle stuff here - I add a row to a Table
}
...
However, the first time I press the button this method is called as I
want, and the next time the Button seems to do a Submit without
calling my event handler. Is it possible to combine the two, so that I
press the button, perform my action in the Command Event Handler and
refresh my WebForm with the changes in my action?


Nov 16 '05 #2

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

Similar topics

2
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
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: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
1
by: Klaus Jensen | last post by:
Subject: Handling events of controls created at runtime I need to render some buttons at runtime based on a database, tie events to them, and handle the events when they fire. In Page_Load I...
8
by: Louis | last post by:
I was trying to display a custom context menu in javascript. I wanted to capture a right mouse click. I added an eventListener to a "div" like this.. element,addEventListener ("click", myfunc,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.