Rich Textbox Problem

Wolfgang (4)

Usenet Archive
Joined
Jul 8, 2008
Messages
4
Reaction score
0
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?
 

Peter Bucher MVP

Usenet Archive
Joined
Jul 16, 2007
Messages
118
Reaction score
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?
 

Wolfgang (4)

Usenet Archive
Joined
Jul 8, 2008
Messages
4
Reaction score
0
Hi wolfgang

Should work.
But be sure to give the control a ID.

What is the produced Output looks like?

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

Usenet Archive
Joined
Jul 16, 2007
Messages
118
Reaction score
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);
}
}
 

Wolfgang (4)

Usenet Archive
Joined
Jul 8, 2008
Messages
4
Reaction score
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); } }

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top