all groups > asp.net webcontrols > october 2003 >
You're in the

asp.net webcontrols

group:

How can I use working Linkbuttons within a Web Custom Control?



How can I use working Linkbuttons within a Web Custom Control? Jan Limpens
10/13/2003 11:29:50 PM
asp.net webcontrols: 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







Re: How can I use working Linkbuttons within a Web Custom Control? Jan Limpens
10/15/2003 10:49:55 AM
hi steve,

it works :)!
and the gizmo with tabbing the event code, whow, i´ll print that on a
tshirt for more people to know ;). that´s a big timesaver! you don´t
happen to know anything similar for the creation of standard get/set
properties, do you?

thanks a lot
jan


[quoted text, click to view]
Re: How can I use working Linkbuttons within a Web Custom Control? Steve Drake
10/15/2003 1:52:44 PM
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]

Re: How can I use working Linkbuttons within a Web Custom Control? Steve Drake
10/15/2003 3:22:26 PM
no for get sets, but you can write a macro.

the tab thing also works for interfaces, type the interface name, hit tab
and it put the code in for you.

Also.... when you need to override from a base class, just type override,
you will see a list of things you can override, hit tab and it will put the
code in for you.

You will need a big t-shirt add all those tips :)

Steve


[quoted text, click to view]

AddThis Social Bookmark Button