?
Solved

Programmaticly assign onclick event to a button

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

Button1.onclick = "MyOnClickRoutine"
0
Comment
Question by:DColin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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