?
Solved

Programmaticly assign onclick event to a button

Posted on 2004-04-30
5
Medium Priority
?
420 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 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