[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Extending Textbox capabilities

Posted on 2009-05-12
16
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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