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

How to set selected tag from code-behind

1 Answer 18 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
KDL asked on 08 Oct 2013, 06:15 PM
Using the TagCloud control, how can I set the selected Tag from the server-side code? I need the TagCloud control pre-select one of the items when the control is loaded. For example if the items = tag1, tag2, tag3, I want to set the initial selection to tag2 in the Page_Load event. How can I achieve this? Thanks!

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 10 Oct 2013, 04:20 PM
Hi Kent,

If you refer to focusing a particular item of the RadTagCloud, you can register a client-side script on the code-behind, which will use the client-side API of the tag cloud to get an item and focus it. The following code sample shows this approach:
<telerik:RadTagCloud ID="RadTagCloud1" runat="server" Width="400px" MaxFontSize="50px">
        <telerik:RadTagCloudItem Text="Russia" Weight="141.9" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Nigeria" Weight="154.7" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Saudi Arabia" Weight="28.6" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Canada" Weight="34.1" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="USA" Weight="309.4" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Sweden" Weight="9.3" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Germany" Weight="81.7" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Turkey" Weight="72.5" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="Japan" Weight="127.3" NavigateUrl="" />
        <telerik:RadTagCloudItem Text="France" Weight="65.4" NavigateUrl="" />

public void Page_Load(object sender, System.EventArgs e)
    RadScriptManager.RegisterStartupScript(this, this.GetType(), "focusTagCloudItem", "Sys.Application.add_load(function () { $find(\"" + RadTagCloud1.ClientID + "\").get_items()[3].get_element().getElementsByTagName(\"a\")[0].focus(); });", true);

This script will retrieve the fourth item in the Items collection of the tag cloud, the one with text Canada.

I hope this helps. Feel free to contact us again if you run into more difficulties.

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 the blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question