473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Event delegate parser

Hello everybody.
Can anyone help me? I'm writing a server control which raises events. On
MSDN I've read a lot about events and saw a bunch of samples illustrating
the mechanism of events. Among those samples I've saw a couple of ones on
which built-in ASP.NET controls featured event initialization right from
ASCX/ASPX code. For example:
<asp:Repeater id="rptMyRepeater" OnItemDataBound="OnMyRepeaterDataBind"
runat="server">
....
</asp:Repeater>

The piece of interest is the OnItemDataBound property. The documentation
says that it initializes the ItemDataBound event for the control. Does
anybody know how to implement this behavior so that the name of the event
handler is supplied in the attribute value? Suppose I'm having a control
nmsp:MyControl which raises the TestEvent event. What should I do to make
this syntax work:
<nmsp:MyControl id="ctlMyControl" runat="server"
OnTestEvent="OnMyControlTestEvent" />
?
Any hint/reference/sample will be appreciated
Thanks,
Kirill Osipov
Nov 18 '05 #1
1 1191
"Kirill Osipov" <ki**********@yandex.ru> wrote in message news:uS**************@TK2MSFTNGP12.phx.gbl...
<nmsp:MyControl id="ctlMyControl" runat="server"
OnTestEvent="OnMyControlTestEvent" /> : : Does anybody know how to implement this behavior so that the name of the
event handler is supplied in the attribute value?


All your control needs to do is expose a public event property, and ASP.NET
does the rest automatically.

For instance, your control needs to declare the following delegate type,

public void delegate TestEventHandler( object sender, EventArgs args);

and then inside of your server control's class you need to have a field
whose type corresponds to the delegate, an event property, and an
virtual method that you call from someplace within your control's logic
that actually fires the event at the appropriate time,

private TestEventHandler test;
public event TestEventHandler TestEvent
{
add { this.test += value; }
remove { this.test -= value; }
}
protected virtual void OnTest( EventArgs e)
{
if ( null != this.test )
this.test( this, e);
}

The OnEVENTNAME attribute of a server control can only bind to
the *public* event handlers on the WebForm, however. When the
event handler is private you'll receive the error message that it's
inaccessible due to it's protection level.
Derek Harmon
Nov 18 '05 #2

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

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
5
by: Ian Richardson | last post by:
I'm writing some code which does one thing when onreadystatechange occurs, e.g. handle.onreadystatechange = function() { blah(handle,other_params) }; ....but sometimes I need to add another,...
1
by: emma middlebrook | last post by:
Hi I want to find out what objects are due to receive an event i.e. those that have added themselves as an event handler via +=. Yes, it's a little pointless perhaps (or can anyone give some...
18
by: Elder Hyde | last post by:
Hey all, A class of mine needs to tell the outside world when its buffer is not empty. The problem is that C# seems to force you to put the event-raising code in the base class. To illustrate,...
4
by: BC | last post by:
Hi all, Just wondering what are the difference between: public event EventHandler MessageNotify; public EventHandler MessageNotify; A friend told me it's related to the accessibility levels.
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...
0
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...
0
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 project—planning, coding, testing,...

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.