473,796 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Create AddressOf for ImageButton

Please help.

I have ImageButtons that are created dynamically and the event to be
called onclick of the button is stored in a database. The event
itself will be prewritten, however it is on a separate .vb page than
the aspx.vb codebehind file. I have not been able to get the button
to fire the event. here is the code:

Dim button as new imageButton
button.imageURL =image.gif
button.ID="butt onName"
AddHandler button.click, AddressOf btnLookup_Click
A separate section in the same .vb file is:
Protected Sub btnLDAPLookup_C lick(ByVal s As Object, ByVal e As
EventArgs)
DO SOMETHING
End Sub

What am I doing wrong? Should it be a protected sub? Does it matter
that the sub is located in a .vb file, with the button initialization,
that is not the same aspx.vb file?

Any help is greatly appreciated.
Nov 18 '05 #1
1 1490
To add more detail I have copied and pasted the code below:

Public Shared Function getImageButton( ByVal buttonID As Integer, ByVal
imagePath As String)

Dim button As New ImageButton
Dim buttonDB As New SAFE.SAFEFuncti ons
Dim dbconnButton As IDbConnection = Nothing
Dim buttonReader As SqlDataReader
dbconnButton = buttonDB.GetCon nection
dbconnButton.Op en()
Dim getButtonSQL As String
getButtonSQL = SAFE.SAFEFuncti ons.getRequestI temDetail(butto nID)
Dim getButtonComman d As New SqlCommand(getB uttonSQL, dbconnButton)
buttonReader = getButtonComman d.ExecuteReader
Do While buttonReader.Re ad
Select Case
buttonReader("R equestConfigura tionObjectTypeP ropertiesID")
Case 8 'image source

button.ImageUrl = imagePath &
buttonReader("R equestObjectVal ue")
Case 22 'Alt Text
button.Alternat eText =
buttonReader("R equestObjectVal ue")
Case 23 'ID
button.ID = buttonReader("R equestObjectVal ue")
Case 24 'On Click Event

AddHandler button.Click, AddressOf
btnLDAPLookup_C lick()
End Select
Loop

buttonReader.Cl ose()
getButtonComman d.Dispose()
dbconnButton.Cl ose()
Return button
End Function

The btnLDAPLookup_C lick is as follows:
Private Sub btnLDAPLookup_C lick(ByVal s As Object, ByVal e As EventArgs)
do something here...
End Sub

Remember, these are both in the same .vb file, but not the aspx.vb for this
page. However, the function is called during the PageLoad function so I
thought this should work.

Again, any help is greatly appreciated.
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5529
by: Jim Mitchell | last post by:
I have some code behind that generates 10 imagebutton controls.... I can not seem to figure out how to trap the onclick event for each image and determine which image was clicked. Can someone help? Thanks in advance. for i = 1 to 10 img = New System.Web.UI.WebControls.ImageButton
2
2166
by: Danny Bloodworth | last post by:
I have a usercontrol (login.ascx) that is very simple. It accepts input through two textboxes, and then the user clicks an Imagebutton to submit. I have a parent form that checks the page security (security level needed) against current user security (stored in the context object) and if user security >= level needed to view page then dynamically loads a content control and displays content
2
3745
by: Jose Suero | last post by:
Hi all I have a dynamically created button, I can add an event handler with: AddHandler button.click, AddressOf static_function This works great, but what I need is to create a function that takes the control, the event and the function as parameters, something like: function addevent(control as object, event as string, functionname as string)
8
4318
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
3
3322
by: sck10 | last post by:
Hello, When a person subits my web page, I do a simple check (validation) and if there are any errors, I create a variable (strValidateText) and set that value to a label on the form. What I am trying to do create an image button along with the html. I am getting the error: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.ImageButton'.
4
3028
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime, as needed, I'm having trouble wiring up its click event procedure. The problem is that when I go to subscribe the ImageButton to the delegate, the ImageButton is <undefined> (i.e., throws the "object not found" exception). Note that I'm using...
6
1921
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create a new thread to display a customer on the screen for example. However, I have a problem with circular references in my objects which means that I have to load the customer object using reflection ie :
1
2880
by: fabrice | last post by:
Hello, I d like to modify the Onclik Event of an ImageButton control in code behind. But when i do it , i get an error. This is ma code : The control is the pasx page :
6
5459
by: RSH | last post by:
Hi, i have a situation where I need to dynamically create objects in a loop. My question surrounds intantiation naming in such a scenerio. Below is a snippet that is basically hardcoding each object. My problem is that I would like to create the objects dynamically but I can't figure out how to do it How would I go about dynamically creating the required objects so that I could be using anywhere from 2 - 10 etc. ?
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.