开发者

How to Get RadButton Toggle State's Text Property At Client Side ? [Telerik ASP.NET AJAX Controls]

开发者 https://www.devze.com 2023-03-01 06:59 出处:网络
I want to Get The Text Property Ofthis using jquery or any other way... Plea开发者_如何学Cse help me....Not sure what text property was being looked for, but I had to do something similar, so

I want to Get The Text Property Of this using jquery or any other way...

Plea开发者_如何学Cse help me....


Not sure what text property was being looked for, but I had to do something similar, so for anyone else looking...

Getting information when the button is invoking the function

Start with your button on your page:

<telerik:RadButton ID="rbtn_State" runat="server"
OnClientClicked="ToggleStateChange" ButtonType="ToggleButton"
ToggleType="CustomToggle">
<ToggleStates>
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/play.png" Selected="true" />
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/pause.png"/>
</ToggleStates>
</telerik:RadButton>

Notice that when the user clicks the radbutton, the ToggleStateChange function is called (be sure to add a script reference to your page if you are using an external js file like me.)

Now, for the function:

function ToggleStateChange(sender, args) {
  //Start by getting all of the information about the current state
  //of the button
    var currentState = sender.get_selectedToggleState();
  //Now, there are a number of functions you can call - Refer to link below      
    var currentImageUrl = currentState.get_imageUrl();  //gets image URL text
}

Getting the information when another element invokes a function

For example, think of an auto collapse all divs button and individual auto collapse/expand button for a single div. If the auto collapse selected was turned on, all divs would toggle (divs.toggle();) and the individual button to collapse or expand the div needed to change from the collapse toggle state to the expand toggle state since the divs are already collapsed.

In the function that is called by the invoking element(in my case the auto collapse all button calling the AutoCollapseAllDivs function), add:

 //Find the button that needs to change toggle states
 //**When using $() to find the button, the structure of the button's 
 //information is not the same as when the button is the sender.**
 //In this case, the toggle information is under _control.
 var button = $('#rbtn_collapse')[0].control;  // note the use of [0]
 //Now pick a get/set method to implement
 //For example, change the toggle state
 button.set_selectedToggleStateIndex(1); //easy way is to set the index

Notes:

Using Q2 2011 Telerik Controls

Using external js file

References:

The basic methods for the radbutton: http://www.telerik.com/help/aspnet-ajax/button-client-side-basics.html

Examples for getting toggle information are a little harder to find, but here is one: http://demos.telerik.com/aspnet-ajax/button/examples/clientsideevents/defaultcs.aspx


You should get the currently selected ToggleState, and then get the text from the ToggleState. Here is a sample code snippet:

var button = $find("RadButton1");
var text = button.get_selectedToggleState().get_text();
alert(text);
0

精彩评论

暂无评论...
验证码 换一张
取 消