Solved

Programmaticly assign onclick event to a button

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

738 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