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

Assign multiple client side methods to one client side event?

1 Answer 287 Views
Input
This is a migrated thread and some comments may be shown as answers.
Austin
Top achievements
Rank 1
Austin asked on 29 Dec 2010, 08:50 PM
I have a RadNumericTextbox and I want to assign two javascript events to fire for the OnValueChanged.

So lets say I have JavaScript methods called MethodA(); and MethodB(); that I want to call.  What I would like to do would be something like this:

<telerik:RadNumericTextBox ID="rntMyTextBox" Type="Number" runat="server"
                    MaxValue="997" EnabledStyle-HorizontalAlign="Right" Font-Size="Small" MaxLength="3"
                    MinValue="0" Width="153px" FocusedStyle-PaddingRight="1px" ShowSpinButtons="true"
                    ClientEvents-OnValueChanged="MethodA(); MethodB();">
 I am able to stack methods on other HTML properties, such as when I add an onChange="alert('A'); alert('B');" property and change the value via the page, then I get the expected message boxes, the first saying A, the second saying B.

So the first question is, can this be done?  If so, what is the format?  I can't seem to make it work.

Secondly, one of the methods I'm adding sets a 'FormHasChanged' bool to True... but based on another forum post I read it would seem the 'OnValueChanged' fires once when the page loads and the control populates the value initially... is there a way to modify this behavior?  The other post suggested tracking the before and after values... this is far from ideal as I would like to be able to generically add a call to set the bool when the value changes.

The big picture is this:

From a random page's code behind I want to be able to call a function I created like so:
//Add the OnChange event to all the appropriate controls on this user control.
ControlManager.AddOnChange(this.Controls, "SetDirtyFlag"true);
The AddOnChange method loops through all the controls in the passed in control set.  For each control, it tries to decide how best to apply an 'onChange' event... ADDING to any existing method defined.  The way I'm trying to do this for a RadNumericEtc is something like :
else if(control is RadNumericTextBox)
{
(control as RadNumericTextBox).ClientEvents.OnValueChanged = (control as RadNumericTextBox).ClientEvents.OnValueChanged + ";" + onChangeString;
//We also want to avoid user tab to the up and down spinner buttons on any RadNumericTextBox controls.
(control as RadNumericTextBox).ButtonDownContainer.Attributes.Add("tabindex""-1");
(control as RadNumericTextBox).ButtonUpContainer.Attributes.Add("tabindex""-1");
}
This way, when I call AddOnChange, the SetDirtyFlag method call would be ADDED to any other method(s) defined to fire when the value changes.  The SetDirtyFlag simply sets the 'FormHasChanged' flag to true, without needing to include any other specific logic.

So my two issues are 1) I can't seem to stack method calls and 2) If the 'OnValueChanged' fires at page load, then the page will ALWAYS think the form has changed... and if I have to track before/after values, then that would require a MASSIVE amount of additional coding...

Thoughts?

1 Answer, 1 is accepted

Sort by
0
Accepted
Cori
Top achievements
Rank 2
answered on 31 Dec 2010, 02:06 PM
Hello Austin,

To answer your first question, you can set multiple methods for the OnValueChanged event by setting it like so:

ClientEvents-OnValueChanged="function(sender,args){MethodA();MethodB();}"

For you second question, I don't see any other way then checking the old and new values if that is how the event works.
Tags
Input
Asked by
Austin
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Share this question
or