473,761 Members | 6,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subscribing to event from Template Column

I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.

I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.

How can I subscribe to the event?

Thanks,
T
Nov 19 '05 #1
3 1219
Hi Tina,

If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the ascx
codebehind file.

Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in this
example: http://www.societopia.net/Samples/Da...Delegates.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.

I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.

How can I subscribe to the event?

Thanks,
T

Nov 19 '05 #2
I guess I'm going to have to learn c# if for nothing other than to follow
the examples....

in VB to handle an event we .....
AddHandler myControl.Timer Event, AddressOf me.HandleTimerE vent
..
..
Protected Sub HandleTimerEven t(byval o as Object, byval e as TimerArgs)
.. code to handle event is here...
end sub

How would the AddHandler code look in the case where myControl is in
DataGrid1?

"Phillip Williams" <Ph************ **@webswapp.com > wrote in message
news:0E******** *************** ***********@mic rosoft.com...
Hi Tina,

If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the
ascx
codebehind file.

Alternatively, you can use event delegates to expose events out of your
ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in
this
example: http://www.societopia.net/Samples/Da...Delegates.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.

I'm trying to figure out how I can subscribe to the event. It can't be
done
at design time because myControl is not one of the recognized controls.
At
run time I would expect to use AddHandler but I can't seem to reference
myControl.

How can I subscribe to the event?

Thanks,
T

Nov 19 '05 #3
Hi Tina,

For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing that
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)

I created here
http://www.societopia.net/Samples/Da...olsEvents.aspx a sample
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
“OnCustomEven t1”. I then included that control in a TemplateColumn on the
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"Tina" wrote:
I guess I'm going to have to learn c# if for nothing other than to follow
the examples....

in VB to handle an event we .....
AddHandler myControl.Timer Event, AddressOf me.HandleTimerE vent
..
..
Protected Sub HandleTimerEven t(byval o as Object, byval e as TimerArgs)
.. code to handle event is here...
end sub

How would the AddHandler code look in the case where myControl is in
DataGrid1?

"Phillip Williams" <Ph************ **@webswapp.com > wrote in message
news:0E******** *************** ***********@mic rosoft.com...
Hi Tina,

If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the
ascx
codebehind file.

Alternatively, you can use event delegates to expose events out of your
ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in
this
example: http://www.societopia.net/Samples/Da...Delegates.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.

I'm trying to figure out how I can subscribe to the event. It can't be
done
at design time because myControl is not one of the recognized controls.
At
run time I would expect to use AddHandler but I can't seem to reference
myControl.

How can I subscribe to the event?

Thanks,
T


Nov 19 '05 #4

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

Similar topics

0
1310
by: Bisbal | last post by:
Hi All, I have created a class that simulates a MDI form by putting the 'child' inside a panel located in the 'parent' form. I had to do this because we use a custom UI that doesn't work properly with standard MDI forms. The constructor of the class is something like SemiMDI(System.Windows.Forms.Form client,System.Windows.Forms.Panel parentArea)
1
410
by: Tina | last post by:
In the ItemDataBound event I know how to reference the text in a text box in a template column: e.item.cells(0).text but I can't figure out how to reference a dropdownlist in a template column: e.item.cells(1).???????? how can I reference the control in the template column so that I can fill it? thanks,
0
951
by: sqlboy2000 | last post by:
All, I have a simple datagrid with one column being a template column that contains a dropdown control. I'd like to be able capture when the index of the dropdown changes and access the value that has been selected. I've tried the datagrid's itemcommand event but it doesn't fire when the dropdown selection changes. Here is the closest solution I could come up with using the onchange event: Private Sub DataGrid1_ItemDataBound(ByVal...
4
4385
by: Souri Challa | last post by:
Hello All, When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the DataGridItem(e.Item.DataItem is null) in the event arguments has no values. Is there any way to access and manipulate the row contents in this case ? Thanks in advance for any insigts in to this. -Souri
7
3342
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
6
6683
by: John Smith | last post by:
How can I find out which control performed PostBack? I have put this code inside my Page_Load event: Response.Write(Page.Request.Params.Get("__EVENTTARGET")) but it doesn't write to response anything when I click on the button inside DataGrid (my asp:Button is located inside my template column togrther with my asp:TextBox). It works fine for DropDownList, which is also inside template column inside DataGrid.
3
3758
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and thawed it out. I built a console app using Microsoft Visual C++ 6 (VC++) and it worked great. Only one line in the header file had to be commented out. I built a console app using Borland C++ Builder 5. The linker complained of references to...
0
1964
by: Andy | last post by:
Probably this quesion was already raised, but I couldn't find any answer to it, even on Google. My question is: I have a plain datagrid on a page, and I'm adding a button column to it. When this button column is in a form of a Link button, ItemCommand event is processed, and code stops nicely on a breakpoint set in the DataGrid1_ItemCommand procedure. When I make one change - type of the button is changed to Push button,...
3
9788
by: =?Utf-8?B?SmFtZXMgTGVubm9u?= | last post by:
I have a gridview that has a button column and a template column with another button in it. When I click on the button column button I can get the row index in the event handler for the CommandArgument parameter. However when I click on the template column button the CommandArgument parameter is "". How can I get the row index when a user clicks on a button in a template column? Thanks, James
0
9345
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
10115
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...
1
9905
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,...
0
9775
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...
0
8780
agi2029
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 projectplanning, coding, testing, and deploymentwithout 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...
1
7332
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
6609
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();...
0
5229
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...
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.