Solved

Extending Textbox capabilities

Posted on 2009-05-12
16
182 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now