Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Add OnClick button event dynamically

Reply
Thread Tools

Add OnClick button event dynamically

 
 
anony
Guest
Posts: n/a
 
      12-14-2003
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


 
Reply With Quote
 
 
 
 
Munsifali Rashid
Guest
Posts: n/a
 
      12-14-2003
To add a server-side event handler, use the following code:

MyButton.Click += new System.EventHandler(MyButton_Click)

where MyButton_Click is as follows:

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

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

myButton.Attributes.Add("onClick", "fnClientSideThing()");

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

Hope this helps,

Mun




"anony" <(E-Mail Removed)> wrote in message
news:Xt%Cb.15334$(E-Mail Removed) m...
> 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



 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      12-14-2003
"anony" <(E-Mail Removed)> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically adding Dropdown, Text Box, Add Button and Remove Button Rocky ASP .Net Building Controls 0 11-08-2006 11:20 PM
Issues Using Javascript confirmation box in conjunction with a button. Attributes.Add("onclick"...) event and GetPostBackEventReference bay_dar@yahoo.com ASP .Net 2 11-06-2006 06:31 PM
asp.net dynamically created button not firing onClick event rsaffy@nuvox.com ASP .Net 7 07-20-2006 09:02 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
dynamically add a table row with onclick cool2005 Javascript 8 05-09-2005 12:46 PM



Advertisments