try
NOTE the lines with a *, these is the bits your were missing to make it
work.
LinkButton yourLinkButton ;
public myClass : WebControl , INamingContainer // * Must Implement
INamingContainer,
// its just a marker interface, very COM like,
//why didn't they use an attribute here ?
// I presume its faster, eg just have code like if (object is
INamingContainer)
protected override void CreateChildControls() // * I believe the property
way is not to create the controls in the render
{
yourLinkButton = new LinkButton();
yourLinkButton.Text = "Press me";
// * if you don't hook into the event why would it generate the
postback script?
// try typing this line, .NET 2003 will write the code for you if you
press tab just after you type +=, hit tab again and it writes the code at
the bottom.
yourLinkButton.Command+=new
System.Web.UI.WebControls.CommandEventHandler(yourLinkButton_Command);
controls.Add(yourLinkButton); // * Add it to the controls collection.
}
protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls(); // This will run the CreateChildControls() if its
needed.
yourLinkButton .RenderControl(writer);
}
private void yourLinkButton_Command(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
// HANDLE YOUR EVENT
}
"Jan Limpens" <removeThis.wb0se9k5n001@sneakemail.com.delete-this.here>
[quoted text, click to view] wrote in message news:OnPh2rfkDHA.2772@TK2MSFTNGP12.phx.gbl...
> hi!
>
> I've got a Web Custom Control within which I'd like to use LinkButtons.
> This looks more ore less like this...
>
> protected override void Render(HtmlTextWriter output)
> {
> output.WriteLine();
> output.WriteFullBeginTag("P");
> LinkButton b = new LinkButton();
> b.Text = "Bla";
> b.RenderControl(output);
> output.WriteEndTag("P");
> }
>
> As a result I get a HTML Link which is way to plain...
>
> <P><a>Bla</a></P>
>
> There is no functionality behind this, no javascript to handle the
> postback, no id, no nothing....
> Even setting Command Names, Arguments and Click Events does not help...
>
> Any help? How can I use working Linkbuttons within a Web Custom Control?
>
> Jan
>
>
>
>
>
>
>
>