Rich Textbox Problem

Discussion in 'ASP .Net Building Controls' started by wolfgang, Jul 8, 2008.

  1. wolfgang

    wolfgang Guest

    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?
    wolfgang, Jul 8, 2008
    #1
    1. Advertising

  2. 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.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
    Peter Bucher [MVP], Jul 9, 2008
    #2
    1. Advertising

  3. wolfgang

    wolfgang Guest

    On 9 Jul., 13:11, "Peter Bucher [MVP]" <>
    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.aspnetzone.de/- ASP.NET Zone, die ASP.NET Communityhttp://www.aspnetzone.de/blogs/peterbucher/- 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
    wolfgang, Jul 11, 2008
    #3
  4. 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.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
    Peter Bucher [MVP], Jul 11, 2008
    #4
  5. wolfgang

    wolfgang Guest

    On 11 Jul., 13:15, "Peter Bucher [MVP]" <>
    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.aspnetzone.de/- ASP.NET Zone, die ASP.NET Communityhttp://www.aspnetzone.de/blogs/peterbucher/- 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
    wolfgang, Jul 11, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay

    Rich TextBox / HTML TextBox

    Jay, Apr 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    15,682
    Steve C. Orr [MVP, MCSD]
    Apr 29, 2005
  2. Jay

    Rich TextBox / HTML TextBox

    Jay, Apr 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    583
    =?Utf-8?B?TG9yZW5j?=
    Apr 28, 2005
  3. Alex Smith
    Replies:
    3
    Views:
    1,115
    Oenone
    Jun 7, 2005
  4. Sean

    How to use Microsoft Rich TextBox control 6?

    Sean, Apr 28, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    489
  5. Hollow Quincy

    rich:dataTable - rich:dataScroller

    Hollow Quincy, Dec 30, 2011, in forum: Java
    Replies:
    5
    Views:
    4,504
    Arved Sandstrom
    Jan 2, 2012
Loading...

Share This Page