Solved

Programmaticly assign onclick event to a button

Posted on 2004-04-30
5
392 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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