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

How to set selected tag from code-behind

1 Answer 76 Views
TagCloud
This is a migrated thread and some comments may be shown as answers.
KDL
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
0
Slav
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">
    <Items>
        <telerik:RadTagCloudItem Text="Russia" Weight="141.9" NavigateUrl="http://en.wikipedia.org/wiki/Russia" />
        <telerik:RadTagCloudItem Text="Nigeria" Weight="154.7" NavigateUrl="http://en.wikipedia.org/wiki/Nigeria" />
        <telerik:RadTagCloudItem Text="Saudi Arabia" Weight="28.6" NavigateUrl="http://en.wikipedia.org/wiki/Saudi_Arabia" />
        <telerik:RadTagCloudItem Text="Canada" Weight="34.1" NavigateUrl="http://en.wikipedia.org/wiki/Canada" />
        <telerik:RadTagCloudItem Text="USA" Weight="309.4" NavigateUrl="http://en.wikipedia.org/wiki/USA" />
        <telerik:RadTagCloudItem Text="Sweden" Weight="9.3" NavigateUrl="http://en.wikipedia.org/wiki/Sweden" />
        <telerik:RadTagCloudItem Text="Germany" Weight="81.7" NavigateUrl="http://en.wikipedia.org/wiki/Germany" />
        <telerik:RadTagCloudItem Text="Turkey" Weight="72.5" NavigateUrl="http://en.wikipedia.org/wiki/Turkey" />
        <telerik:RadTagCloudItem Text="Japan" Weight="127.3" NavigateUrl="http://en.wikipedia.org/wiki/Japan" />
        <telerik:RadTagCloudItem Text="France" Weight="65.4" NavigateUrl="http://en.wikipedia.org/wiki/France" />
    </Items>
</telerik:RadTagCloud>

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.

Regards,
Slav
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 the blog feed now.
Tags
TagCloud
Asked by
KDL
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or