Solved

Extending Textbox capabilities

Posted on 2009-05-12
16
190 Views
Last Modified: 2013-11-08
Hi

I have Created a project of type "ASP.NET Server Control"

The class is inherited from WebControls

I have changed the base class to Textbox


How can I render the textbox in  RenderContents

protected override void RenderContents(HtmlTextWriter output)
0
Comment
Question by:KaranGupta
  • 8
  • 7
16 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24363377
use the HtmlTextWriter object to render an input tag with the type "text" like this:
	protected override void RenderContents(HtmlTextWriter writer)
	{
		//base.RenderContents(writer);
		writer.RenderBeginTag(HtmlTextWriterTag.Input);
		writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
		writer.AddAttribute(HtmlTextWriterAttribute.Name, this.ClientID);
		//etc...
 
		writer.RenderEndTag();
	}

Open in new window

0
 
LVL 9

Expert Comment

by:tetorvik
ID: 24363504
To get it work you'll need to override Render, not RenderContents method. Method content should be like GuitarRich provided.

protected override void Render(HtmlTextWriter writer)
{
...
}

Open in new window

0
 

Author Comment

by:KaranGupta
ID: 24372852
How can I get label in Render function
I have used the following code(code in code section)

but I am not getting label


output.RenderBeginTag(HtmlTextWriterTag.Label);                
output.AddAttribute(HtmlTextWriterAttribute.Value, "karan");                

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:GuitarRich
ID: 24372884
did you render the end tag?
0
 

Author Comment

by:KaranGupta
ID: 24372907
Hi

I am using following code in Render function
output.RenderBeginTag(HtmlTextWriterTag.Label);
                output.AddAttribute(HtmlTextWriterAttribute.Value, "karan");      
                output.RenderEndTag();

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24372933
did you comment out the
base.Render(writer)
line?
also try using the Write methods like this:

		writer.WriteBeginTag("label");
		writer.Write("karan");
		writer.WriteEndTag("label");

Open in new window

0
 

Author Comment

by:KaranGupta
ID: 24372944
where to comment base.Render

because as such there is no line as base.Render in the code

But I have overridden the render function
0
 

Author Comment

by:KaranGupta
ID: 24372963
When I write this code (code section)

I am getting a textbox
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
output.AddAttribute(HtmlTextWriterAttribute.Name, this.ClientID);
output.RenderEndTag();

Open in new window

0
 

Author Comment

by:KaranGupta
ID: 24372993
Hi

My class is inherited from Control class that is why I am getting this problem

when I am inheriting this class from TextBox class then it is working fine

May I know the reason for this
0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373136
do you want a composite control? ie a label combined with a textbox? if so it would probably be better to use a WebUserControl and drop the 2 controls in there rather than render them yourself.
0
 

Author Comment

by:KaranGupta
ID: 24373195
I want a custom control in which I want to use the dll further in the project
0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373281
and do you want that to be a label next to a textbox?
0
 

Author Comment

by:KaranGupta
ID: 24373299
Yes I want label next to textbox

and this label should be visible on a particular value of the property
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24373384
ok - this works in a control I have just tried - I think this is linked to your other question:
			//base.Render(writer);
			writer.RenderBeginTag(HtmlTextWriterTag.Span);
 
			writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
			writer.AddAttribute(HtmlTextWriterAttribute.Name, this.ClientID);
			writer.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
			writer.RenderBeginTag(HtmlTextWriterTag.Input);
 
			writer.RenderEndTag();
 
			if (this.MTBText != string.Empty && this.MTBErrorMessageControlType == MTBErrorMessageControl.LABEL)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.For, this.ClientID);
				writer.RenderBeginTag(HtmlTextWriterTag.Label);
 
				writer.Write(this.MTBText);
				writer.RenderEndTag();
			}
 
			writer.RenderEndTag(); // span

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373386
I have put all that in the Render overrided method.
0
 

Author Comment

by:KaranGupta
ID: 24373429
it works thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 104
Adding where clause to entity statement c# 1 48
Dictionary and array of [N] size - performance tuned 12 41
Calculating percentage 2 30
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question