[lnkForumImage]
TotalShareware - Download Free Software

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


 

wolfgang

7/8/2008 1:47:00 PM

I'd like to create a rich textbox which inherits from TextBox:

public class MyTextBox : TextBox
{
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
LinkButton button = new LinkButton();
button.Text = "Button";
button.RenderControl(writer);
}
}

But in the output produced the linkbutton is no longer a LinkButton
but just plain text. If i inherit from CompositeControl everything
woks find but then my testbox is no longer a TextBox.

Is there a way to make my linkbutton work and my textbox remains a
TextBox?


4 Answers

Peter Bucher [MVP]

7/9/2008 11:11:00 AM

0

Hi wolfgang

> public class MyTextBox : TextBox
> {
> protected override void Render(HtmlTextWriter writer)
> {
> base.Render(writer);
> LinkButton button = new LinkButton();
> button.Text = "Button";
> button.RenderControl(writer);
> }
> }
Should work.
But be sure to give the control a ID.

What is the produced Output looks like?

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspn... - ASP.NET Zone, die ASP.NET Community
http://www.aspn...blogs/peterbucher/ - Auf den Spuren von .NET

wolfgang

7/11/2008 6:36:00 AM

0

On 9 Jul., 13:11, "Peter Bucher [MVP]" <peter.buc...@aspnetzone.de>
wrote:
> Hi wolfgang
>
> >    public class MyTextBox : TextBox
> >    {
> >        protected override void Render(HtmlTextWriter writer)
> >        {
> >            base.Render(writer);
> >            LinkButton button = new LinkButton();
> >            button.Text = "Button";
> >            button.RenderControl(writer);
> >        }
> >    }
>
> Should work.
> But be sure to give the control a ID.
>
> What is the produced Output looks like?
>
> --
> Gruss, Peter Bucher
> Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerlandhttp://www.aspne... ASP.NET Zone, die ASP.NET Communityhttp://www.aspnetzone.de/blogs/pet... Auf den Spuren von .NET

Hi Peter,

the output produced is a TextBox and the text of the button. The
functionality of the LinkButton is lost. It's just text and not a
link.

Wolfgang

Peter Bucher [MVP]

7/11/2008 11:16:00 AM

0

Hi Wolfgang

Do it like so:
public class MyTextBox : TextBox
{
protected override void OnInit(.....) {
LinkButton b = new LinkButton();
b.ID = "someID";
b.Text = "someText";
this.Controls.Add(b);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
button.RenderControl(writer);
}
}

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspn... - ASP.NET Zone, die ASP.NET Community
http://www.aspn...blogs/peterbucher/ - Auf den Spuren von .NET

wolfgang

7/11/2008 12:25:00 PM

0

On 11 Jul., 13:15, "Peter Bucher [MVP]" <peter.buc...@aspnetzone.de>
wrote:
> Hi Wolfgang
>
> Do it like so:
>     public class MyTextBox : TextBox
>     {
> protected override void OnInit(.....) {
> LinkButton b = new LinkButton();
> b.ID = "someID";
> b.Text = "someText";
> this.Controls.Add(b);}
>
>         protected override void Render(HtmlTextWriter writer)
>         {
>             base.Render(writer);
>             button.RenderControl(writer);
>         }
>     }
>
> --
> Gruss, Peter Bucher
> Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerlandhttp://www.aspne... ASP.NET Zone, die ASP.NET Communityhttp://www.aspnetzone.de/blogs/pet... Auf den Spuren von .NET

Many thaks, Peter. The control is working, now. The source code now
is:

public class MyTextBox : TextBox
{
protected override void OnInit(EventArgs e)
{
LinkButton button = new LinkButton();
button.Text = "Button";
this.Controls.Add(button);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
base.RenderChildren(writer);
}
}

Wolfgang