Solved

Programmaticly assign onclick event to a button

Posted on 2004-04-30
5
395 Views
Last Modified: 2008-02-01
How do I do this correctly. Thanks.

Button1.onclick = "MyOnClickRoutine"
0
Comment
Question by:DColin
5 Comments
 
LVL 7

Expert Comment

by:culshaja
ID: 10957148
AddHandler Button1.Click, AddressOf MyOnClickRoutine

James :-)
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 10957218
Hi,
try this

in the case of C#
                   button.Click += new EventHandler(this.Button_Clicked);
in the case of Vb.Net use
                   AddHandler button.Click, AddressOf Me.Button_Clicked

hope that this helps you.

Regards,
Venki
0
 

Author Comment

by:DColin
ID: 10958495
'Click' is not an event of 'System.Object'. Is the error I get when I run the following code.

Dim SubmitBtn
SubmitBtn = New Button()
SubmitBtn.Text = "OK"
SubmitBtn.Id = "OKButton"
AddHandler SubmitBtn.Click, AddressOf SubmitBtn_Click
Panel1.Controls.Add(SubmitBtn)
0
 
LVL 1

Accepted Solution

by:
CouldNotFindAnyOtherUsername earned 500 total points
ID: 10958565
Try Changing your code as follows:

Dim SubmitBtn as System.Web.UI.Webcontrols.Button
SubmitBtn = New Button
SubmitBtn.Text = "OK"
SubmitBtn.Id = "OKButton"
AddHandler SubmitBtn.Click, AddressOf SubmitBtn_Click
Panel1.Controls.Add(SubmitBtn)


GK
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 10958606
Hi,
try this code

        Dim SubmitBtn As New Button
        SubmitBtn.Text = "OK"
        SubmitBtn.Name = "OKButton"
        AddHandler SubmitBtn.Click, AddressOf SubmitBtn_Click

regards,
venki
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now