Howdy, I think I have a good question!
I'm creating a usercontrol, and within this usercontrol, I'm dynamically
creating controls (imagebuttons to be exact), that the user can click on
which will cause a postback to occur.
My problem is, I can't seem to be able to get the handlers to work within
the user control, to determine which control has been clicked, and what to
do with it from there.
I want these events to be handled within the user control itself, and not
the page that has the user control.
Here is what I've been doing:
'I'm adding this imagebutton to a tablecell I'm dynamically creating as
well, for simplicity i'm not showing that this code is part of a for each
loop, and it can be ran many times...
Dim dImage as ImageButton = new ImageButton
AddHandler dImage.click, AddressOf DeleteButton_Cl ick
dImage.imageurl = "../images/delete.gif"
dImage.tooltip = "Delete this Item"
tblcellDelete.C ontrols.Add(dIm age) 'tcDelete is a TableCell
tblRow.Controls .Add(tcDelete) 'trow is a TableRow
tblShow.Control s.Add(trow) 'tblShow is a Table
Then I create the event handler in the user control
Sub DeleteButton_Cl ick(ByVal sender As Object, ByVal e As
System.Web.UI.I mageClickEventA rgs)
Response.Write( "clicked an image?")
End Sub
For now I'm just using Response.write with a breakpoint on that line to see
if that code executes. Unfortunately the DeleteButton_Cl ick Sub is never
called, the page just posts back. Can someone tell me the proper way to
handle events for dynamically created controls within user controls?
Thanks!
--Michael 2 4228
I've done a similar thing myself, emphasis on SIMILAR.
I fix my similar problem I had to reload all of the dynamic controls on each
postback, the viewstate info then allowed the events to take place.
Hope that helps
"Michael Ramey" <raterus@localh ost> wrote in message
news:Ox******** ******@TK2MSFTN GP11.phx.gbl... Howdy, I think I have a good question!
I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which will cause a postback to occur.
My problem is, I can't seem to be able to get the handlers to work within the user control, to determine which control has been clicked, and what to do with it from there.
I want these events to be handled within the user control itself, and not the page that has the user control.
Here is what I've been doing:
'I'm adding this imagebutton to a tablecell I'm dynamically creating as well, for simplicity i'm not showing that this code is part of a for each loop, and it can be ran many times...
Dim dImage as ImageButton = new ImageButton
AddHandler dImage.click, AddressOf DeleteButton_Cl ick dImage.imageurl = "../images/delete.gif" dImage.tooltip = "Delete this Item" tblcellDelete.C ontrols.Add(dIm age) 'tcDelete is a TableCell tblRow.Controls .Add(tcDelete) 'trow is a TableRow tblShow.Control s.Add(trow) 'tblShow is a Table
Then I create the event handler in the user control
Sub DeleteButton_Cl ick(ByVal sender As Object, ByVal e As System.Web.UI.I mageClickEventA rgs) Response.Write( "clicked an image?") End Sub
For now I'm just using Response.write with a breakpoint on that line to
see if that code executes. Unfortunately the DeleteButton_Cl ick Sub is never called, the page just posts back. Can someone tell me the proper way to handle events for dynamically created controls within user controls?
Thanks! --Michael
Worked great, just one thing, the button i'm writing the event for is a
"delete" button, so on a postback, I wouldn't want it to appear again. I
suppose I can search and delete the control before it is rendered again.
Thanks for the info, it did help.
"Felbrigg" <so*****@micros oft.com> wrote in message
news:Od******** ********@tk2msf tngp13.phx.gbl. .. I've done a similar thing myself, emphasis on SIMILAR. I fix my similar problem I had to reload all of the dynamic controls on
each postback, the viewstate info then allowed the events to take place.
Hope that helps
"Michael Ramey" <raterus@localh ost> wrote in message news:Ox******** ******@TK2MSFTN GP11.phx.gbl... Howdy, I think I have a good question!
I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which will cause a postback to occur.
My problem is, I can't seem to be able to get the handlers to work
within the user control, to determine which control has been clicked, and what
to do with it from there.
I want these events to be handled within the user control itself, and
not the page that has the user control.
Here is what I've been doing:
'I'm adding this imagebutton to a tablecell I'm dynamically creating as well, for simplicity i'm not showing that this code is part of a for
each loop, and it can be ran many times...
Dim dImage as ImageButton = new ImageButton
AddHandler dImage.click, AddressOf DeleteButton_Cl ick dImage.imageurl = "../images/delete.gif" dImage.tooltip = "Delete this Item" tblcellDelete.C ontrols.Add(dIm age) 'tcDelete is a TableCell tblRow.Controls .Add(tcDelete) 'trow is a TableRow tblShow.Control s.Add(trow) 'tblShow is a Table
Then I create the event handler in the user control
Sub DeleteButton_Cl ick(ByVal sender As Object, ByVal e As System.Web.UI.I mageClickEventA rgs) Response.Write( "clicked an image?") End Sub
For now I'm just using Response.write with a breakpoint on that line to see if that code executes. Unfortunately the DeleteButton_Cl ick Sub is
never called, the page just posts back. Can someone tell me the proper way to handle events for dynamically created controls within user controls?
Thanks! --Michael
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Gadlin |
last post by:
Hi there! First off, let me apologize for the basic
question... I'm very new to .NET programming.
I'm building a web site using VB.NET, and am trying to
include several custom user controls. One of these user
controls handles the navigation.
This user control polls the database for the section
headers that the current user has access to. It grabs
those headers from the database, let's say 5 of them, then
|
by: Altramagnus |
last post by:
I have 30 - 40 type of different window.
For each type I need about 20 instances of the window.
When I try to create them, I get "Error creating window handle"
My guess is there is a maximum number of window handle, because if I reduce
to about 2 instances of each window,
it can run. But not 20 instances of each window.
Does anyone know what the problem is? is it really because it exceeds the
maximum number of window handle?
|
by: theComputer7 |
last post by:
I cut down the code to make this half way understandable... I have
read Data Grid girls caution about over use of dynamic controls. I
truly believe what I am doing requires dynamically inserted user
controls.
Worse I'm trying to add dynamic user controls from within a repeater
loop (looping through attributes)... I bind to a function in the code
behind and pass in the attribute.
<asp:repeater id="rAttributes" Runat="server">
|
by: sleigh |
last post by:
Hello,
I'm building a web application that will build a dynamic form based
upon questions in a database. This form will have several different
sections that consist of a panel containing one to many questions.
To keep it simple, I'll describe the basics of what I'm trying to
design.
I've created a TextBox composite control that consists of a label for
|
by: Michael |
last post by:
Need some help trying to read values from web controls - specifically
*finding* the controls (like a drop down list) - that are added
dynamically added within an asp:panel control.
The page contains multiple panels within the form. The panels appear
at different times - for our argument, let's say panel 1 appears
first, users clicks a submit button and then
panel 1 disappears and panel 2 appears, etc.
When clicks on the submit button...
| |
by: mytestemailaccount |
last post by:
Hi,
Hope you can help.
I am relatively new to all this but would appreciate the groups help.
The scenario:
I am c# and asp.net to create a web application. The web page contains
a user control (.ascx).
|
by: John |
last post by:
Hi all,
I need finality on this once and for all please.
I have a main page which contains a couple of placeholders and within these
placeholders, depending on what the user presses, I load different user
controls. This loading of user controls is done within the code-behind of
the main page. The problem is that before loading a user control in place of
another, I need to do a Controls.Add then a Controls.Remove so the viewstate
is...
|
by: Larry Grady |
last post by:
Anyone up for a challenge?
I've been struggling with this for a few days and was hoping someone could
help me. Pouring through all the messageboards I just can't find the
solution.
We have a GridView that needs to be dynamically designed, depending on what
collection of fields our uses want to edit for their product data. We have
400+ fields of information per product so they're selecting a subset of those
fields to edit.
|
by: Tarscher |
last post by:
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |