473,672 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to attach special events to a custom server control ?

Hey everybody,

I'm looking for a way to attach non-void events to a server control i
wrote.
Relevant code parts:

the control:

mycontrol : WebControl
{
public delegate string myEventHandler( string s);
public event myEventHandler OnClick;
...
...
}

the .aspx page portion:

<%
string func1(string s)
{
return s.Revers();
}
%>
<cc1:myContor l OnClick="func1" />

Now, what i want to do is to attach the click event of the control to a
function which returns a string, contrary to 'plain' events of .net
which are of void type and get 'sender' and 'e' as event-arguments.

The error i get is a compilation-time error saying 'func1' cannot be
converted from string type to a delegate. If so, i guess i have to
write a type converter which converts the function name to a delegate
that will invoke it. Is it the only way ? am i trying to do an
impossible thing while trying to attach a non-void function to an event
?

May 12 '06 #1
2 1315
Your question doesn't make sense. Take a look at the following which I
copied:

<cc1:myContor l OnClick="func1" />

So, if your event handler returns a string, you want to assign it to
"OnClick"?

I think you need to start over from what the requirement is, and figure out
a solution that makes sense. In other words, what you've posted is a partial
(and unworkable) solution to some requirement that needs to be fulfilled.
What exactly is the requirement (not the solution)?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

<ha*********@gm ail.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
Hey everybody,

I'm looking for a way to attach non-void events to a server control i
wrote.
Relevant code parts:

the control:

mycontrol : WebControl
{
public delegate string myEventHandler( string s);
public event myEventHandler OnClick;
...
...
}

the .aspx page portion:

<%
string func1(string s)
{
return s.Revers();
}
%>
<cc1:myContor l OnClick="func1" />

Now, what i want to do is to attach the click event of the control to a
function which returns a string, contrary to 'plain' events of .net
which are of void type and get 'sender' and 'e' as event-arguments.

The error i get is a compilation-time error saying 'func1' cannot be
converted from string type to a delegate. If so, i guess i have to
write a type converter which converts the function name to a delegate
that will invoke it. Is it the only way ? am i trying to do an
impossible thing while trying to attach a non-void function to an event
?

May 12 '06 #2
I think you aren't understanding events, delegates, functions and other
methods. The OnClick attribute of a control tag is used only to assign
an event handler, with the proper signature, to the OnClick event.

The OnClick is an Event, Func1 should be an EventHandler. Both of which
will be sub routines.

In order to assign a value you must choose an attribute that is bound
to a property i.e. Text as in Text="<%=myValu e()%>" where Text is the
public property on the Control and MyValue() is a method that returns a
string value, from your container (Page) and is properly modified
(public, protected, etc)

-Rick

May 12 '06 #3

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

Similar topics

3
4072
by: Aymer | last post by:
i created a new button object. how do i attach an event on it? thanx for your help. Dim cc As ColorConverter = new ColorConverter() Dim b = new button() b.ID = "SelectedDate" b.BorderStyle = 1 b.forecolor = cc.ConvertFromString("red") b.BackColor = cc.ConvertFromString("white")
1
7313
by: Mark | last post by:
Hi, I'm writing user controls with custom events. I have a parent custom event that exposes some abstract methods and some custom events. I have also created some new user controls that derive from the parent custom control and add some text boxes, labels, buttons etc...
7
2682
by: Colin Young | last post by:
I have a UserControl that contains a calendar control. The calendar is not raising events (month navigation, date selections, etc.). I've checked that the OnSelectionChanged event has a handler being registered. Is there anything else obvious or otherwise that I've missed? Is there a problem using it in a UserControl? Thanks Colin
0
1350
by: Mike | last post by:
Hi, I have a class library (dll) in which I defined a class for a custom control (called PlaceHolder). In a separate Web project, I created a custom control (called Template.ascx) that contains three "PlaceHolder" controls, as follows: <SIGMA:NAMINGPLACEHOLDER id="Activities" runat="server"></SIGMA:NAMINGPLACEHOLDER></td> <SIGMA:NAMINGPLACEHOLDER id="Body" runat="server"></SIGMA:NAMINGPLACEHOLDER></td> <SIGMA:NAMINGPLACEHOLDER...
1
1973
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can point out the really obvious and stupid thing I'm overlooking here. :) I have a custom control that provides a tasklist similar to what you get in certain parts of Office. On the client it consists of a bunch of nested, named and id'ed divs with...
1
1544
by: Martin | last post by:
Hi, I have been having trouble rasing events in my custom (composite) server controls. To demonstate my problem I put a small control together with a single button on it and included the code below. Now what I want is when the button is clicked I wish to catch the event (this is happening correctly) and then raise the event "MyCustomEvent". "MyCustomEvent" is raise in the event "btn_Click" (at bottom of email)
12
2785
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
3
7793
by: George Jordanov Ivanov | last post by:
Folks, I am implementing a WebUserControl, which will have its own custom event StateChanged. Now, I want to add this event to the Events tab in the control properties, so that the users of my control can set the event handler from this tab. However, I can't see my custom StateChanged event over there and I don't know what is the reason. Setting BrowsableAttribute to the public event property doesn't solve the problem. Any other ideas? ...
2
2734
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page Begin PreInit aspx.page End PreInit 5,38454603734274E-05 0,000054 aspx.page Begin Init 8,96405962016187E-05 0,000036 aspx.page End Init 0,00072941040948794 0,000640 aspx.page Begin InitComplete 0,000772971258380746 0,000044
0
8498
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
8418
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
8940
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
7458
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, 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...
1
6251
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
5718
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
4237
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
4434
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2833
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 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.