Welcome Guest Search | Active Topics | Sign In | Register

EditableLabel clientsideonchange problem Options
WMP
Posted: Friday, September 28, 2012 5:36:07 AM
Rank: Advanced Member
Groups: Member

Joined: 7/6/2011
Posts: 30
Hi I am trying to use the clientsideonchange event to call a javascript that copies the new value from one editablelabel to another. So if I'm calling the script from label1 to copy the new value of label1 to label2, the value that is actually coppied is the value of label1 BEFORE it was changed. Is it supposed to work this way? My test script is below.
Quote:


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script id="test" language="javascript">
<!--
function copyvalue() {

var editableLabel1 = eo_GetObject("EditableLabel1");
var editableLabel2 = eo_GetObject("EditableLabel2");

var Label1Value = editableLabel1.getValue();
editableLabel2.setValue(Label1Value);
}
-->
</script>


<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
EditableLabel1: <eo:EditableLabel ID="EditableLabel1" runat="server" ClientSideOnChange="copyvalue" Hint="EditableLabel1" >
</eo:EditableLabel>
EditableLabel2: <eo:EditableLabel ID="EditableLabel2" runat="server" Hint="EditableLabel2">
</eo:EditableLabel>
</div>
</form>
</body>
</html>

eo_support
Posted: Friday, September 28, 2012 1:45:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Yes. That's the designed behavior. ClientSideOnChange is called BEFORE the change is accepted with the following argument:

Code: JavaScript
function ClientSideOnChangeHandler(sender, s)
{
     //sender is the EditableLabel control that raised this event
     //s is the new value

     //Inside this function you can modify s and return a new value
     //For example, you can have code like this to make sure the
     //content of the EditableLabel is no more than 10 characters long
     if (s.length > 0)
         return s.substr(0, 10);
     else
         return s;
}

The value returned by this function is then accepted by the EditableLabel and can be queried through getValue. In your case, you can simply add those two arguments into your handler and call editableLabel2.setValue with the second argument. If your function does not return any value, the original EditableLabel will take whatever value you entered.

Hope this helps.

Thanks!
WMP
Posted: Tuesday, October 2, 2012 4:54:01 AM
Rank: Advanced Member
Groups: Member

Joined: 7/6/2011
Posts: 30
Fantastic, it works, thank you! (I would never have thought of that :))


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.