Skin not applied to CompositeControl at design time

Hi there,  

I am using Visual Studio 2008 and I have a very simple custom web server control class named TestControl. The class inherits from CompositeControl, with two child controls: Label myLabel and TextBox myTextBox. In my TestWebForm the Theme attribute is set appropriately to a Theme where I have defined skins with font attributes for "regular" Label and TextBox controls and for the TestControl class.  At run time everything is fine: the skin (font attributes) is applied to child controls, but I cannot force the ASP.NET VS designer to apply skin attributes at design time!

Actually, I have found two ways to apply the skin to child controls:

  • skins for "regular" asp:Label ans asp:TextBox controls have to be defined in the skin file and that's all
  • skin for custom TestControl has to be defined in the skin file and font attributes have to be mapped in CreateChildControl() (eg. myTextBox.Font.Size = this.Font.Size;)

I have tried also:

  • to set StylesheetTheme in the @page directive, instead of Theme attribute and to call ApplyStyleSheetSkin() method for child controls in CreateChildControls()
  • to manually apply SkinID for TestControl
  • to map Style attributes of child controls in CreateChildControls(), instead of font attributes (eg. myLabel.Style[HtmlTextWriterStyle.FontSize] = this.Font.Size.ToString();)

Nothing helps! The only way I have managed to get child controls font attributes displayed somehow at design time, is to set Font.Name and Font.Size in the TestControl constructor or to manually set these properties in the designer's property grid. But it is not what I really need. Another interesting thing is that when I inherit a control from eg. TextBox control, not CompositeControl, the designer applies the skin (if skin is defined for custom TextBox control, not for "regular" TextBox). Is it possible to get the design time behavior as I expect? Please, help! Here is the source code (there is no code in TestWebForm codebehind class):

 

SKIN FILE

<%@ Register assembly="Calculus.Web" namespace="Calculus.Web.UI.WebControls._TestControls" tagprefix="ctc" %>

<asp:Label runat="server" Font-Names="Tahoma" Font-Size="11px" />

<asp:TextBox runat="server" Font-Names="Tahoma" Font-Size="11px" />

<ctc:TestControl runat="server" Font-Names="Tahoma" Font-Size="11px" />

 

TEST WEBFORM

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestWebForm1.aspx.cs" Inherits="Calculus.ProximoWeb._TestPages.TestWebForm1" StylesheetTheme="DefaultTheme" %>

<%@ Register assembly="Calculus.Web" namespace="Calculus.Web.UI.WebControls._TestControls" tagprefix="ctc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Test Web Form 1</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<br />

<ctc:TestControl ID="TestControl1" runat="server" />

<br />

<br />

</div>

</form>

</body>

</html>

 

 

TEST CONTROL

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Linq;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace Calculus.Web.UI.WebControls._TestControls

{

[
ToolboxData("<{0}:TestControl runat=server></{0}:TestControl>")]

public class TestControl : CompositeControl

{

private Label myLabel = new Label();private TextBox myTextBox = new TextBox();

 

public TestControl()

{

}

protected override void CreateChildControls()

{

this.Controls.Clear();

myLabel.Text = "My Label";

myLabel.Font.Name = this.Font.Name;

myLabel.Font.Size = this.Font.Size;

myTextBox.Text = "Some text";

myTextBox.Width = 100;

myTextBox.BackColor = System.Drawing.
Color.White;

myTextBox.Font.Name = this.Font.Name;

myTextBox.Font.Size = this.Font.Size;

Controls.Add(myLabel);

Controls.Add(myTextBox);

}

}

}

0
kunta
4/2/2008 10:44:29 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

6 Replies
786 Views

Similar Articles

[PageSpeed] 7

 You have to turn on theming like on a regular control on a webform

myTextBox."Turn on theming" , whatever intellisense tells you, then select the skin or theme

I don't remember the exact syntax for it in CS

this.Font.Name, Font.Name needs a value

myTextBox.Font.Name = "Tahoma" or whatever is presented by the intellisense

 


 

0
jkirkerx
4/4/2008 10:18:56 PM

Thank you jkirkerx, nice try! I have found what you meant, I suppose:

myTextBox.EnableTheming = true;
myTextBox.ApplyStyleSheetTheme(Page);

Doesn't help! Sad Anyone could try my example, please?

 

0
kunta
4/5/2008 12:20:12 AM

 It's not a complete fix, just the next step you needed to make it work. But you on the right track.

Now you need to grab the property element for styles in your control property panel, and apply the actual style to it.

You can manually apply the style = "MyStyle" to test first, and then apply the property value later after you confirm that it works. 

 

0
jkirkerx
4/5/2008 5:17:44 PM

Thank you again, but I am a little confused whit this answer. How do you think "to grab the property element for styles in your control property panel, and apply the actual style to it"? There are properties: CssClass, which is not the skin, SkinID which is not working and a bunch of style properties like BorderColor, BorderStyle, Font etc. What do you mean with "the property element for styles"?

Nevertheless, I think this is not the point. I repeat: the skin is applied to the main composite control (its span tag is properly rendered), but the skin is not applied to the CHILD CONTROLS. I don't want to programmatically apply each skin attribute for each child control (this is not theming and skinning) and I even don't know how would it be possible (there is no way to grab the skin properties from the skin files anyhow).

0
kunta
4/6/2008 8:55:45 AM

Your right , SkinID, my bad.

If you go into designer view, and click on your control, you can access the properties of that control.   Just like a regular control such as textbox.

In the list of properties, you'll see SkinID. Type in the name or ID of your SkinID and set the value. 

In your Control code, you can grab the SkinID value.  In vb, It's [SkinID] with the square brackets. I don't know what it is in CSharp off the top of my head.

myTextBox.SkinID = [SkinID] 'for VB

myTextBox.CssStyle = [CssStyle]

This is how you can grab predefined values from the property box, and use them in your control. 

This is just help on the Control Side issue of your post. I'm not offering help on the skin side issue of your post. I don't do skins.

 I've messed around with skins, but ended up using themes.  The themes were merely CSS Style collections that could be changed on the fly through code.  The skins were system wide in which all Label, TextBox, Button, etc would acquire that look and feel. If I made cooler looking sites such as gaming sites, or music sites, I would use skins. I stopped using themes, because of the large amount of time it takes to create good looking themes.

 


 

 

0
jkirkerx
4/6/2008 6:12:48 PM

 Hi,

 I has the same problem as you and after I google for a while I found a solution. In design time "theme" doesn't work but "styleSheetTheme" works. You can edit following line in web.config to apply theme in design time.

<pages pageBaseType="PageBase" styleSheetTheme="YourThemeName" />
You can read more from http://blogs.msdn.com/markjo/archive/2006/09/22/766048.aspx
 or http://forums.asp.net/p/905541/1000300.aspx

 

0
artit
5/3/2009 2:19:56 PM
Reply:

Similar Artilces:

Skin not applied at design time for CompositeControl child controls
I am using Visual Studio 2008 and I have a very simple custom web server control class named TestControl. The class inherits from CompositeControl, with two child controls: Label myLabel and TextBox myTextBox. In my TestWebForm the Theme attribute is set appropriately to a Theme where I have defined skins with font attributes for "regular" Label and TextBox controls and for the TestControl class.  At run time everything is fine: the skin (font attributes) is applied to child controls, but I cannot force the ASP.NET VS designer to apply skin a...

Designing time of Custom Server control
Hi, I built a date picker control which includes a textbox and an image. The first time I finished it, I drag from toolbox and put on the form designer, it showed me a textbox and an image. But after a few times changing and recompiling, now, after i drag it from the toolbox, it does not show a textbox and an image, but only text [DatePicker "DatePicker"]. It looks very strange. Any idea to make the design time looks well? There is plenty stuff on that topic on the internet: Rather general and advanced: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dn...

How to create custom properties for aspx page which should refelect in design time properties window itself.( as like as custom server control).
Hi. I need to create the custom properties for aspx page itself where those custom properties should refelet in the properties window at the design time as like as other custom server controls. I tried pageBase class which will have cusom properties for page and inherited that pageBase to my aspx page . But its refelecting the code  behind file not in design time. I need to accss those aspx page custom properties at the design time itself in properties window as like as other custom server control.I appriciate your help. [FYI: my scenerio is customer ...

Picture for Custom Server Control for Design Time
 I created Custom Server Control and I want to use my picture for my Control in Designer in form where I use my control.And when my Control on Toolbox I want use my picture too.   I **think** you need to put an attribute at the top of your custom control class definition. It **might** be this attribute, but I'm not positive about that. [ToolboxBitmap(typeof(System.Web.UI.WebControls.Image))]...

Custom Server Control broken: design-time
I have an implementation of custom server controls that are designed to reside inside a custom page class that inherits from System.Web.UI.Page, like all code-behind pages.  This page implements an interface so that my control can make requests from the parent page. After conversion, the application runs fine--everything works OK, BUT in VS2005, I cannot design my pages anymore, as all my controls are broken...they just have those gray blobs reporting an exception, which I can work-around with enough garbage-code, but... This worked in ASP1.1, VS2003: protected override void OnI...

How to Set the Design Time Visibility of a Custom Server Control
Hello, I need to set my custom web control unvisible/visible on the design surface at design time. I've implemented a ControlDesigner and did override the GetDesignTimeHtml()-Method. In this method i get the html - markup the base-classes (webcontrol) GetDesignTimeHtml - Method creates for rendering the control at design time on the design surface and modify this html - markup by setting the style  display attribute from "inline-block" to  "none".  Unfortunately this causes no effect. It seems that VS handles the html - markup a little bit different tha...

server control
HI allI have created a server control that draws out a hyperlink with some extended capabilities like adding a querystring etc.  The control raises an event that I handle in the containing page.  I do this by adding the "onControlAdded" attribute to the server control as shown below (in bold.)<cc1:hyperlink onControlAdded="Bindit" runat="server" text="Shopping Cart" navigateurl="shoppingcart.aspx" enableviewstate="false" id=Hyperlink1>Currently, I drag the control from the toolbox, drop it on the page, and then I have to type in the onControlAdded="Bindit" attribute...

Problem with Themes at design-time for custom-built Server Controls
I'm putting the finishing touches on a couple of Server Controls, and I seem to have hit a wall. These are custom DHTML controls that rely heavily on user styling and have been built specifically for the Theme features of ASP.NET 2.0. At run-time, they work great, Themes and all. But at design-time, it's a different story... For some reason the tag attributes that are set in the .skin file are NOT set at design-time, though the tag attributes set in the actual .aspx file are. For example, my skin might say that the background color is red, and the web form might say that the text is "Here'...

How can I change appearance of my Custom server control in DESIGN TIME ?
How can I change appearance of my Custom server control in DESIGN TIME when DefaultProperty is changed  (from Properties Window) ?I don't understand how to see object of ChoiceCity from code of his designer (clsChoiceCityDesigner). And how to do refresh of design view  from property SelectedIDhere fragment of my class: [DefaultProperty("SelectedID")] [Designer(typeof(clsChoiceCityDesigner))]public class ChoiceCity : CompositeControl, INamingContainer { public int SelectedID { set { if (this.DesignMode) { // here I want to do refresh ...

Custom server control subclassed from Panel not working correctly at design time
Control: Custom server control inherited from WebControls.PanelDesigner inherited from WebControls.PanelDesigner Problem: When the control is dropped on the designer its design time width is zero Solution: Protected Overrides Sub OnBehaviorAttached()Dim loFieldSetPanel As FieldSetPanel = MyBase.ComponentIf loFieldSetPanel.Width.IsEmpty Then Me.MapPropertyToStyle("Width", "100%") Unwanted Side Effect: When the control is subsequently resized by dragging, the Width property's UnitType is Unit.Percentage instead of Unit.Pixel Possible workarounds, in order of preference: Determ...

My Custom Server Control Doesn't Resized at Design-Time
Hi,I'm Developing a new Custom Server Control for ASP.NET.For this component i have write a class descendent from ControlDesigner to provide Designer-Support in the IDE.But I Have a little problem with "WIDTH & HEIGHT" properties at Design Time in the IDE, My Component doesn't Resize and have a Fixed "width & Height" Look BUT when i set a dummy width and hieght in design-time,these properties effects on Run-Time.!!!In the other hand ,These properties work Fine but at design-time my component's look doesn't Refreshed Also i've overrided the "AllowResize" property as follow: public cl...

Custom Server Control - Moving within the VS.Net Designer
Hi, I have created a custom server control that inherits from System.Web.UI.Control. I would like my end users to be able to drag and move the server control in the VS.Net IDE. I presume I have to expose the left/top style properties but can't find anything in the documentation or via google. Any pointers, links or code would be great :) R Hmmm, Inherit from System.Web.UI.WebControls.WebControl or just use the default Create Web Control project in the .Net IDE Can't believe I spent 1 hour looking for this :) Any element can be movable in VS.NET. What it really does is ...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Dragging controls in to a custom control at design time
I am creating a custom control that will contain a panel so that developers can drag other controls into it at design time. If I create a control that inherits from Panel this works no problem. But I need a composite control that may contain more than one Panel and this does not seem to work. I'm assuming I need to hard code support for dragging in controls. Does anyone have any ideas??...

Web resources about - Skin not applied to CompositeControl at design time - asp.net.custom-server-controls

Scott Banwart - .NET - Scott Banwart
Scott Banwart - The Rogue Technologist About Me .NET BizTalk Books Business Cloud Development Distributed Weekly Integration Linux Meta Ruby ...

Resources last updated: 11/27/2015 8:27:06 PM