Theming custom created WebParts in ASP.NET 2.0

G

Guest

I have created my own WebPart using code, it is not derived from a UserControl.
Inside this WebPart I create a Calendar Control and add it to the WebParts
Control collection.

Now I want to apply a theme to this Calendar that is inside my WebPart. How
do I do that? I have created a theme and added a definition for a calendar.
The theme is applied to a calendar that is not inside the WebPart, but it is
not applied to the one inside.
 
S

Steven Cheng[MSFT]

Hi c_kimbell,

Welcome to MSDN newsgroup.
As for the custom WebPart with a Calendar inside it, is it possible that we
define a public property on the Custom webPart which represent the Theme of
the inside Calendar control? Then, we any one assign a new value for this
property, the nested calendar's Theme value will be changed accordingly.

In addition, for .NET 2.0 and VS.NET whidbey beta issues, I suggest you
also try posting in the following web forum:

http://forums.microsoft.com/msdn/

since there are some other experienced members who may have some good ideas.

Thank you,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Thanks for suggesting the ASP.NET forums, I have posted there now as well.

Here are some more details on what I have tried;
1. On the webpart I have exposed the Calendar as a property with the name
FromCalendar.
2. I have added the following to the .skin file

<%@ Register Assembly="IMK.WebParts" Namespace="IMK.WebParts"
TagPrefix="IMK" %>

<IMK:IMKDateWebPart runat="server">
<FromCalendar BackColor="#FFFFCC">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</FromCalendar>
</IMK:IMKDateWebPart>

Am I on the right track?
 
S

Steven Cheng[MSFT]

Hi c_kimbell,

Thanks for your followup.
As you mentioned that
=================


1. On the webpart I have exposed the Calendar as a property with the name
FromCalendar.
2. I have added the following to the .skin file

<%@ Register Assembly="IMK.WebParts" Namespace="IMK.WebParts"
TagPrefix="IMK" %>

<IMK:IMKDateWebPart runat="server">
<FromCalendar BackColor="#FFFFCC">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</FromCalendar>
</IMK:IMKDateWebPart>
=======================

I'm not sure whether this will cause error since I haven't tested it.
However, IMO, I'd prefer expose a single string property on my custom web
control which represent the nested child calendar's Theme(or
stylesheettheme). Since the ASP.NET 2.0 's Theme are mostly for those
simple type properteis (such as string, int), I think just exposing a
single string type property will be much better). You can do the actual
Theme adjusting in the Property's Setter method.
How do you think ?

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

I get your point about using simple strings. One thing though, say you expose
a color, this can be specified using a name like 'Red' or it may be specified
using hex notation, like '#FFCC66'. The controls require a Color object, how
does one map between the different representations and the Color object. Are
there any utility classes I can use?

I have now done a bit more experimenting. If I declaratively add the webpart
to a webpartzone, then the theme is correctly applied. If I add the same
webpart to the zone using a catalog, the style is not applied. The catalog
I'm adding from is a custom created one, not one of the predefined types.

Any suggestions?
 
S

Steven Cheng[MSFT]

Hi c_kimbell,

For those Color field, the ASP.NET runtime's ControlParser will help parse
the property value into the correct object instance. And for Color, there
is the ColorTranslator class which can be used from convert string color
value to System.Drawing.Color instance. For example:

string htmlColor = "Blue";
//or string htmlColor = "#3344ee";
// Translate htmlColor to a GDI+ Color structure.
Color myColor = ColorTranslator.FromHtml(htmlColor);

For the applying theme for custom created catalog's webpart, I'm not sure
whether this is ok. As far as I know, since the ASP.NET2.0 runtime apply
theme for controls in the page's PreInit event, so any change on Theme
after that event (for example in Page_load ..., post back event) will not
work in the first loading....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top