How Do I Implement the IButtonControl interface in my custom control?

D

daokfella

I basically want to recreate a linkbutton control. My control inherits
webcontrol. I override the TagKey property to render an A tag
(hyperlink).

I need this link to postback to the server so I can respond to Click
and Command events. My biggest problem is needing to know how to
implement the events. This is what I've done so far:

public event EventHandler Click;
public event CommandEventHandler Command;

protected virtual void OnClick(EventArgs e)
{
if (Click != null) Click(this, e);
}
protected virtual void OnCommand(CommandEventArgs e)
{
if (Command != null) Command(this, e);
}

Question 1: What is the proper code to register the postback script in
the href?
Something like?
this.Attributes["href"] = Page.ClientScript.GetPostBackEventReference
(new PostBackOptions(this, this.CommandArgument, "", true, true,
false, true, true, this.ValidationGroup));

Question 2: How do I wire up the events in the postback? Do I need to
implement IPostBackEventHandler?
Something like?

public void RaisePostBackEvent(string eventArgument)
{
OnClick(new EventArgs());
OnCommand(new CommandEventArgs(this.CommandName,
this.CommandArgument));
}

This seems to work, but I'm concerned that I'm not handling the
CommandArgument correctly.

Can anybody get me on the right track? I know it seems that I should
just inherit LinkButton, but I can't. This control actually inherits a
basecontrol that inherits webcontrol.
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top