473,586 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add OnClick button event dynamically

Hi,

I'm trying to dynamically add a button to my ASP.NET / VB page. I can't
seem to figure out how to add a routine to the OnClick event. Any insight
would be greatly appreciated!

Thanks,
Brian
Nov 18 '05 #1
2 3574
To add a server-side event handler, use the following code:

MyButton.Click += new System.EventHan dler(MyButton_C lick)

where MyButton_Click is as follows:

private void MyButton_Click (object sender, System.EventArg s e)
{
// Your button click code here.
}

If you want to do something client-side in the onClick event, use:

myButton.Attrib utes.Add("onCli ck", "fnClientSideTh ing()");

This code will fire the client-side javascript function called
fnClientSideThi ng() when the button is clicked.

Hope this helps,

Mun


"anony" <no**@m.com> wrote in message
news:Xt******** ************@tw ister.tampabay. rr.com...
Hi,

I'm trying to dynamically add a button to my ASP.NET / VB page. I can't
seem to figure out how to add a routine to the OnClick event. Any insight
would be greatly appreciated!

Thanks,
Brian

Nov 18 '05 #2
"anony" <no**@m.com> wrote
I'm trying to dynamically add a button to my ASP.NET / VB page. I can't
seem to figure out how to add a routine to the OnClick event. Any insight
would be greatly appreciated!


Brian,
For VB.NET, take a look at AddHandler and RemoveHandler statements.

For more information, see:
http://msdn.microsoft.com/library/en...onremoveon.asp

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


Nov 18 '05 #3

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

Similar topics

4
39446
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets invoked when I click it. newcol = doc.createElement("TD"); newbutton = doc.createElement("input"); newbutton.name = "newChange"+__uid;
2
18556
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 } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
4
2252
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML source:
0
3145
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where there are tabs at the top with "submenu" buttons showing below the selected tab. The data that defines the tabs and submenus is stored in an XML file...
4
2574
by: Mark Rae | last post by:
Hi, VS.NET 2003 on WinXPPro, both with all the latest patches and updates, etc... I've got a very simple WebForm which is used either to add a new record to a SQL Server database or edit a record. Depending on whether I'm adding or editing, I need to do slightly different validation, so I'm trying to set the form's Save button's onclick...
2
5039
by: showens | last post by:
I have a table that has rows appended dynamically, based on the item selected from a dropdownlist. The rows have a number of cells, one with a literal control using the text of the dropdownlist, several checkboxes, and a button. I am trying to use the button to delete the newly-added row if it was added by mistake. The row with its...
7
3563
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid the button is added to is created at run time? here is code from my aspx page......
3
6485
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick event. I'm stumped with this one, any assistance would be appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://...
4
1966
by: mcelary | last post by:
When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button was created in code behind page. Public Sub rosterAddControls() Dim myBtn As New Button() myBtn.Style.Item("z-index") = "100" ...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
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.