Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Rich Textbox Problem

Reply
Thread Tools

Rich Textbox Problem

 
 
wolfgang
Guest
Posts: n/a
 
      07-08-2008
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?


 
Reply With Quote
 
 
 
 
Peter Bucher [MVP]
Guest
Posts: n/a
 
      07-09-2008
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
 
Reply With Quote
 
 
 
 
wolfgang
Guest
Posts: n/a
 
      07-11-2008
On 9 Jul., 13:11, "Peter Bucher [MVP]" <(E-Mail Removed)>
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
 
Reply With Quote
 
Peter Bucher [MVP]
Guest
Posts: n/a
 
      07-11-2008
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
 
Reply With Quote
 
wolfgang
Guest
Posts: n/a
 
      07-11-2008
On 11 Jul., 13:15, "Peter Bucher [MVP]" <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rich:dataTable - rich:dataScroller Hollow Quincy Java 5 01-02-2012 08:59 PM
I want to open a pdf file in Rich TextBox ... Alex Smith ASP .Net 3 06-07-2005 12:21 PM
How to use Microsoft Rich TextBox control 6? Sean ASP .Net Web Controls 3 04-29-2005 03:16 PM
Rich TextBox / HTML TextBox Jay ASP .Net 5 04-28-2005 11:15 PM
Rich TextBox / HTML TextBox Jay ASP .Net 1 04-28-2005 02:56 PM



Advertisments