473,412 Members | 2,096 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,412 software developers and data experts.

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:myContorl 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 1302
Your question doesn't make sense. Take a look at the following which I
copied:

<cc1:myContorl 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*********@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.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:myContorl 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="<%=myValue()%>" 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
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
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...
7
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...
0
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...
1
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...
1
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...
12
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...
3
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...
2
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...
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
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...
0
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,...
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
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,...
0
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...

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.