Themed PrimaryIconUrl

2 posts, 1 answers
  1. Matt
    Matt avatar
    33 posts
    Member since:
    Nov 2010

    Posted 17 May 2013 Link to this post

    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
  2. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 22 May 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top