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

How to Call a Javascript Function on DataBound RadPanel Bar

1 Answer 76 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Prava kafle
Top achievements
Rank 1
Prava kafle asked on 06 Aug 2010, 09:29 PM
Hi,
I have a databound RadPanelBar  and I want call a javascript function  on clicking one of the RadItem.  I used "OnClientItemClicked" but it did not help. Any Idea why it is not working and how to fix it?

DataBinding:
           RadPanelBar1.DataSource = dt;
            RadPanelBar1.DataFieldID = "ID";
            RadPanelBar1.DataFieldParentID = "ParentID";
            RadPanelBar1.DataTextField = "Label";
            RadPanelBar1.DataValueField = "KeyInCommand";
            RadPanelBar1.DataBind();



protected void RadPanelBar1_ItemDataBound1(object sender, RadPanelBarEventArgs e)
    {
        RadPanelItemCollection radItems = RadPanelBar1.Items;
        AttachClientEventtoRadItems(radItems);
    }


 private void AttachClientEventtoRadItems(RadPanelItemCollection radItems)
    {
        foreach (RadPanelItem radItem in radItems)
        {
            string itemValue = radItem.Value;
            if (radItem.Controls.Count == 1)
                  AttachOnClickEvent(radItem);
        }
    }

private void AttachOnClickEvent(RadPanelItem radItem)
    {
        string itemValue = radItem.Value;
        if (string.Equals(itemValue, "ZOOM_PREVIOUS", StringComparison.CurrentCultureIgnoreCase))
        {
            //String csname1 = "PopupScript";
            //String cstext1 = "<script type='text/javascript'>" + "function DoClick() { Map_Map1.ZoomToPrevousExtent(); alert('added'); return false; }</" + "script>";
            //NextGenProject.ParentPage.RegisterClientScriptBlock(csname1, cstext1);

            radItem.Attributes.Add("OnClientItemClicked", "OnClientItemClicked");
        }
    }

JavascriptFunction :
function OnClientItemClicked(sender, args) {
    Map_Map1.ZoomToNextExtent();
    alert("Button Is Clicked");
}    

1 Answer, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 09 Aug 2010, 02:28 PM
Hello Prava kafle,

You can not attach an event handler specifically for an item. Instead, you can create a single event handler (handling the ClientItemClicked event of the RadPanelBar) and inside of it determine which element is currently clicked.

Here is a nice little reference how to create the handler: http://www.telerik.com/help/aspnet-ajax/panel_panelbar_onclientitemclicked.html

Hope this is helpful for you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
PanelBar
Asked by
Prava kafle
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or