How to attach special events to a custom server control ?

H

harel.moshe

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
?
 
K

Kevin Spencer

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.
 
R

Rick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top