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