This is a migrated thread and some comments may be shown as answers.

[Solved] Themed PrimaryIconUrl

1 Answer 87 Views
Button
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 17 May 2013, 01:27 PM
Hello,

I've got a RadButton with a custom icon working, but I want to use an image from my App_Themes/Blue/Images folder.

I can hardcode the Url like this:
<telerik:RadButton ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click">
    <Icon PrimaryIconUrl="App_Themes/Blue/Images/ButtonImage.gif" PrimaryIconLeft="5" PrimaryIconTop="5" />
 </telerik:RadButton>

But I want to do something like this:
<telerik:RadButton ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click">
    <Icon PrimaryIconUrl='<%# GetThemedUrl("Images/ButtonImage.gif")%>' PrimaryIconLeft="5" PrimaryIconTop="5" />
</telerik:RadButton>

protected string GetThemedUrl(string path)
{
     string url = "~/App_Themes/" + this.Theme + "/" + path;
     return url;
}


However I get an exception saying:

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. Telerik.Web.UI.RadButtonIcon does not have a DataBinding event.

Can this be done? Is there a better way?

Thanks in advance,
Matt

1 Answer, 1 is accepted

Sort by
0
Accepted
Danail Vasilev
Telerik team
answered on 22 May 2013, 10:52 AM
Hi Matt,

The RadButton is not a databound control, therefore you cannot use databinding expressions upon it. What you can do, instead of that is to access its properties in the code behind (for example in Page_Load() event) and set the desired values to them. For example:
ASPX:
<telerik:RadButton ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click">
    <Icon PrimaryIconUrl="" PrimaryIconLeft="5" PrimaryIconTop="5" />
</telerik:RadButton>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    btnLogin.Icon.PrimaryIconUrl = GetThemedUrl("Images/ButtonImage.gif");
}
 
protected string GetThemedUrl(string path)
{
    string url = "~/App_Themes/" + this.Theme + "/" + path;
    return url;
}


Regards,
Danail Vasilev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Button
Asked by
Matt
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or