How to reuse css styles from Telerik RadControls for ASP.NET Ajax - asp.net

Telerik RadControls have builtin support for skinning and uses CSS to style all their controls. However, when plugging these controls into an existing website, what is the best way to merge the styles of the existing site with RadControls own styles?
Update: Given the following options (thanks to Zhaph):
Add the RadControl's CSS to my site
Make the RadControls look more like my site
Add my sites CSS selections to the RadControl style lists
What would be the best option?
Option 2 would require that I maintain two sets of styles going forward.
So preferably option 1. That would enable reuse of the RadControls style system across the site, e.g. have buttons and simple controls look the same.
Update 2 (moved from my answer):
I ended up doing a combination. Using the FormDecorator enables reuse of the RadControls styles on my own buttons and inputs. Also, copying the skins provided by Telerik into my ASP.Net theme enabled customizing the skins.

I have to admit, I've not used the RadControls for some time - we used the CMS RadEditor on a few CMS sites, and that could automatically pick up your style sheets, and add the classes to its list, or you could add some manually.
Looking that the documentation, some bits might help:
RadEditor CSS Classes and Their Use - Although usually these are added automatically by the controls I thought?
The link for 1. also tells you how to do this
A couple of options
External CSS Files, which states "By default RadEditor for ASP.NET AJAX uses the CSS classes available in the current page", but also shows how to load other style sheets.
Using the ToolsFile.xml - Scroll down to the <class> element.

I just wanted to add; the FormDecorator only applies css to certain types of controls. If you have a control that isn't styled you can access the Telerik resources like this:
.cs File - have a public property like follows:
public string HeaderDivBackgroundURL
{
get
{
{
string backgroundURL = string.Empty;
string skin = ((MainMaster)Page.Master).AppSkin;
backgroundURL = Page.ClientScript.GetWebResourceUrl(typeof(RadSplitter), "Telerik.Web.UI.Skins." + skin + ".Splitter.slideTitleContainerBgr.gif");
return backgroundURL;
}
}
}
In the aspx page (in a RadCodeBlock), just have an internal style sheet to read from that property:
<tel:RadCodeBlock runat="server">
<style type="text/css">
.telerikBackgroundMock
{
background: url('<%= HeaderDivBackgroundURL %>') repeat-x;
}
</style>
</tel:RadCodeBlock>
I found this very useful for applying Telerik skins to non-Telerik control in a way that would still be dynamic and change with any skin changes.

As an update to this thread, there is now an online "Style Builder" for the Telerik AJAX and MVC tools that enables visual configuration/customization of the built-in skins:
http://stylebuilder.telerik.com/
This tool eliminates the need to understand CSS class definitions for each control and lets you easily customize one of the built-in themes to better match your site.

Related

How to set control properties in css?

Is there a way to set this kind of properties in css?
So I can use the same calendar and be more organized with my code
<asp:Calendar ID="Calendar1" runat="server" Height="189px" CssClass="Calendar"
ondayrender="CalendarRender" TitleStyle-BackColor="#00718F" TitleStyle-ForeColor="White" ShowGridLines="true" TitleStyle-BorderStyle="Solid" TitleStyle-BorderWidth="1px" TitleStyle-BorderColor="Black" SelectedDayStyle-ForeColor="#281dc9" SelectedDayStyle-Font-Bold="true" DayHeaderStyle-BorderColor="Black" DayHeaderStyle-BorderWidth="1px" DayHeaderStyle-BorderStyle="Solid"
onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
Assuming you're talking about properties such as:
TitleStyle-BackColor="#00718F" TitleStyle-ForeColor="White"
... etc..
Your best bet would be to render the calendar to a page, check its source and see what style it adds. You can then extract this out for use in CSS.
UPDATE
This page has some of the selector names for you, along with what they control ASP.Net Calendar Control Custom Theme Format using CSS
If you want to be more organized, and don't want your project to become like 'spaghetti' in future, use CSS file for css properties. Do not embed this properties in headers, unless this is the only way to solve current issue. This is bad for you, and for all who will work with your project.
I've met lot of legacy projects, wasting too much time to find why some dom element's behaviours differs from what I need.
Just specify CssStyle property in your aspx markup, and it will be mapped to real css class.
And add description for this class in css file.

How to change TextButton Style in Gxt 3.0

I want to change style of textbutton like i want to add background image and i want to change background color using GXT 3.0
someone help me plzzz
Thanks in advance
GXT 3 has a cleaner way to handle these kind of requirements. You have to use Appearance API which is provided in Sencha 3. Here is the key points which is involved in this process.
Appearance Interface, implementation and substitution
Styling with CssResource
Use ClientBundle to fetch css resources
XTemplates to apply styles/properties to mark-ups
In this case what you need to do is to implement an appearance for TextButtonCell (because TextButton uses TextButtonCell as the appearance) and provide required styles using css Style resource (annotating actual .css file path as source) . For example
public interface TextButtonResources extends ClientBundle
{
#Source("TextButton.css")
Style style();
}
Then substitute the built-in TextButtonCell appearance with your one.
<replace-with class="fullyQualifiedNameToYourButtonCellAppearanceClass">
<when-type-is class="com.sencha.gxt.cell.core.client.ButtonCell.ButtonCellAppearance" />
</replace-with>
This blog post has a comprehensive details on this concept
Ext GWT 3.0 Appearance Design
First you set this style in your client side java code:
aButton.addStyleName("my_button_style");
Alternatively, you can use setStyleName() method or even change specific style attributes with setStyleAttribute().
After you've done that in your client side java code, you can define the style in a css file that's loaded for the page.
You can also change the style after component's been rendered. It should properly refresh appearance of your button.

is there a simple way to remove the "ct100" prefix from a .NET user control?

Long story short, dozens of pages use no master page. For a new module I created a master page with a menu control (menu control exists already) so I can get the same look across the six or so pages I'm creating now. Since the content page uses the master page, the Menu control has its name changed to ct100_Menu1 instead of just Menu1. Wouldn't be an issue except someone decided to use the exact name of the control for the CSS that styles the menu, by its exact ID (e.g. CSS is Menu1 a { /* stuff */ }). So the menu won't render properly because I'm using a Master Page and not just copying the code.
I cannot change the CSS code in the menu file as it could break something, so is there any way that I can change the control to not display that pesky ct100 without having to add any tools or mess with creating my own custom control (as I can't replace the Menu.ascx control, although I might be able to modify it to add CSS classes) or is my only choice to either not use a master page or copy the menu CSS into another file and set it properly?
Feel kind of stuck between a rock and a hard place because the code was deliberately written so you cannot use Master Pages and nobody ever went back to change it.
You should set the ClientIdMode to Static. Here's more information from MSDN. Note: This is .NET 4.0 only.
In earlier versions, I would recommend styling off of classes as you can't really control what the name will be everywhere that you use it (as you found out).
If you are on ASP.net 4.0, you can set the ClientID property of the controls.
Otherwise, you're in for a world of hurt as in: Custom Control, ASP.net Literals or JavaScript to change the IDs.
Are you using .NET 4? If so, you can set this on your control:
<asp:SomeControl ClientIDMode="Static" />
Just add the new name to the CSS - without removing the old (since you said that was an issue):
ctl100_Menu1 a,
Menu1 a { /* stuff */ }
If you are using ASP.NET 4.0, you can override the ClientId rendering mode, either per control, or for all controls. For instance:
<my:Menu runat="server" Id="Menu1" ClientIDMode="Static" />
This will enforce that the value "Menu1" is preserved as the client side Id for the element that is rendered. (see here).
What I would recommend though, is apply a CSS class to the menu element, and then adjust the CSS rules around a class. E.g.,:
#Menu1 a {
... to:
#Menu1 a,
div.menu a {
... etc
To "correct" this behavior for your entire web application, look in your web.config for the following tag:
<system.web>
...
<pages ... clientIDMode="*something*">
</pages>
...
</system.web>
Remove the clientIDMode="*something*" property specification. Just take it out.
Yay.

Applying Custom Style to ASP.Net Calendar control

I want to apply custom css to my calendar control. I have applied the same at corresponding locations for e.g.
e.Cell.CssClass = "highlight";
clndrEvt.TodayDayStyle.CssClass = "currentDay";
clndrEvt.OtherMonthDayStyle.CssClass = "OOB";
clndrEvt.NextPrevStyle.CssClass = "dayTitle";
However when i render the control, my styles are not reflected.
When i check 'View Source' it applies my classes (italic) and ALSO applies in-line styles (underlined) along with it, which overwrites my styles. For example,
class="highlight" align="center" style="color:White;background-color:Silver;width:14%"
Can anyone help me out with this? To be very specific how to remove those in-line styles (by using which properties) from the HTML by settings properties of calendar control.
I have tried few, but that did not work.
e.Cell.Attributes.CssStyle.Clear();
e.Cell.Attributes.Add("Style", string.Empty);
clndrEvt.Style.Clear(); // clndrEvt is my calendar control
I had a similar issue recently with a project I had inherited. I worked out that the styling was being added via the Master.skin in app_themes. Might be worth a check there.

Applying Existing Tablestyle to a Gridview

I'm working on a web-enabled version of our existing winforms project. Gridviews seem to be an ample replacement for the datagrids that we've been using. We have extensive table styles written for the old datagrids. Is it possible to reuse this code to apply a style to a gridview?
If a re-write is necessary, what is the best way to style the gridviews?
I don't think there is an easy way to port styled from datagrids to gridviews.
You might consider using the CSS Friendly Control Adaptors as a mechanism for applying the styles:
Using themes and skin files is what you need.
Check this link :
http://msdn.microsoft.com/en-us/library/ykzx33wh(VS.80).aspx
You can copy style from datagrids to gridviews via the CopyFrom() method.
To copy a header style from a datagrid to a grid view:
GridView1.HeaderStyle.CopyFrom(DataGrid1.HeaderStyle);
Footer Style:
GridView1.FooterStyle.CopyFrom(DataGrid1.FooterStyle);
Hope this helps.
The GridView control has several properties of type TableItemStyle (FooterStyle, HeaderStyle, RowStyle, etc).
These TableItemStyle properties contain a method called CopyFrom that expects a System.Web.UI.WebControls.Style. You won't be able to copy styles for your WinForms DataGrid using this method.
Your quickest path is probably to rewrite and use the FooterStyle, HeaderStyle, RowStyle, etc properties of the GridView.

Resources