How to Call a Javascript Function on DataBound RadPanel Bar

2 posts, 0 answers
  1. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 06 Aug 2010 Link to this post

    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");
    }    

  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 09 Aug 2010 Link to this post

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