[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Onclick event wireup for a custom server control

Charles Bretana Jr.

1/2/2003 6:21:00 AM

I want to implement, for a custom server control, that
same functionality that allows you to attach an attribute
to an <asp:button /> tag, called onclick, as in:

<asP:Button id="myBtn" runat="Server"
onclick="myFunction" />,

that causes the asp.net ISAPI filter to look for a
function named myFunction(object, EventArgs) in the code
behind, and AUTOMATICALLY wire up the client side onclick
to that code behind function. (By Automatically, I mean
without having to add a line of code to the page the
custom control resides on, adding a reference to the page
level function to the controls Delegate.)

I know this can be done... You can do it with most web
server controls (asp:button, asp:Link, etc... I just can't
figure out how to implement it within a custom control.
1 Answer

Jesse Ezell

1/4/2003 9:53:00 PM

0

You can do this many ways. One is to implement the
IPostBackEventHandler or IPostBackDataHandler interfaces.
It can be complex though.

The other way is to just use a button control in your
composite control, wire the event handler to an private
method and then do something like this:


public event EventHandler Click;

private void OnMyButtonClick(object sender, EventArgs e)
{
if(Click != null) Click(this, EventArgs.Empty);
}

--Jesse