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

Connecting a Javascript function to a C# method

1 Answer 213 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 20 Mar 2014, 09:41 PM
I am using Telerik AJAX UI 
V2014.1.225.40.

I am a newbie to both Telerik and Visual 2012 but I am
learning fast.

I added a RadToolBar control to my WebPage and a RadPanelBar
on the left-hand side.  I noticed that on
the RadPanelBar property list, there is a property called “Visible”.  When this is set to false, the PanelBar
disappears.  Very cool!

So next, I wanted to see if I could make the PanelBar appear
(RadPanelBar.Visible=true) when the user clicked on a RadToolBar item (a C#
method in my Default.aspx.cs called “RadToolBar1_ButtonClick”).  So, I noticed that in the list of properties
for RadToolBar, there is a property called “OnClientButtonClicked”.  When I put an “event name” on that property,
Telerik created a JAVA Script HTML function that was empty.

First, what do I put into that empty function.

Second, what do I modify inside my Default.aspx.cs program
that would connect that JAVA Script Function to the method with the code that
sets the Property RadToolBar.Visible to true. 
I looked at the examples and could not found one that matched my needs.

How do I do that?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Mar 2014, 03:32 AM
Hi Daniel,

I guess that you want to attach OnClientButtonClicked event of RadToolBar from code behind and in that event you want to set the RadPanelBar visibility as true. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadToolBar ID="RadToolBar1" runat="server">
    <Items>
        <telerik:RadToolBarButton Text="Button1">
        </telerik:RadToolBarButton>
        <telerik:RadToolBarButton Text="Button2">
        </telerik:RadToolBarButton>
    </Items>
</telerik:RadToolBar>
<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Style="display: none;">
    <Items>
        <telerik:RadPanelItem Text="Item1">
        </telerik:RadPanelItem>
        <telerik:RadPanelItem Text="Item2">
        </telerik:RadPanelItem>
    </Items>
</telerik:RadPanelBar>

C#:
RadToolBar1.OnClientButtonClicked = "ButtonClick";

JavaScript:
function ButtonClick(sender, args) {
    var panelbar = $find("<%=RadPanelBar1.ClientID %>");
    panelbar._element.style.display = "block";
}

Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or