Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subclass textbox
Message
From
06/07/2003 17:55:36
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00807291
Message ID:
00807303
Views:
20
>Hi guys,
>I'm trying to create some we custom controls fro all the webform controls, I started with text box. I created a textbox control with the foll code. I placed it on the toolbox, then dragged it on to a webform. But the problem is it does not look like a normal textbox, it just says web custom control and I cannot see it at run time on the browser. Am I doing anything wrong ? can someone help me please.
>
>
>*** text box subclassed control code in a separate project.
>
>using System;
>using System.Web;
>using System.Web.UI;
>using System.Web.UI.WebControls;
>
>namespace cyberlogic.basetextbox
>{
> public class basetextbox : TextBox
> {
> protected override void Render(HtmlTextWriter w)
> {
> this.Text = "Cyberlogic Base WEB TextBox control";
> this.BorderWidth = 1;
> this.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid ;
> this.BorderColor = System.Drawing.Color.LightBlue;
> }
> }
>}

You shouldn't override the Render method if you are creating a custom control based on a single base class (textbox, in this case). You can assign values to the properties that belong to the base class in the Load method, or you can assign the properties a default value by re-decalring them in your class definition with a default assignment (not sure what the syntax is in C#).

Actually, if the only difference between the base class and your custom class is default values for some properties, you would be better served by using a style sheet in the web form. However, if you have other code that must go into the Render method, you still have to call the Render method of the base class in your overridden Render method.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform