Solved

Extending Textbox capabilities

Posted on 2009-05-12
16
183 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now