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

_text and _ClientState

2 Answers 227 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 22 Aug 2011, 09:41 PM
I noticed that telerik textboxes render as three seperate input controls (two of which are hidden) with variations on the name of the original control.  Given the name "yourtextbox", the three resulting controls will be:

yourtextbox
yourtextbox_text
yourtextbox_ClientState

This looks like it is used by Telerik to hold original and new values on the client side to detect whether the contents of a control were changed from their original value by a user, before a postback to the server happens.  I suspect that the contents of these various input controls are compared, and when they hold different values it is deemed the contents of a control were indeed changed.

Is there a Telerik JQuery method I can call in javascript on the client side that uses these fields to determine whether a control was actually changed by a user BEFORE a postback is done?  I want to display a confirm save dialog to the user should they try to move away from a page that they changed prior to saving it.  To do this, I currently pass an attribute on each control that has the original loaded value, so I can compare it to what the control holds at the time the user moves off the page.  But, I would prefer to use a native Telerik method that does this should one exist.

Andy

2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 25 Aug 2011, 11:36 AM
Hello Andy,

You could check if the current value of the input is the same as it's default value:
if ( $get("RadTextBox1").defaultValue == $get("RadTextBox1").value)
{
    //the value is the same
}
Or:
var textbox = $find("RadTextBox1");
var domElement = textbox.get_element();
 
if (domElement.defaultValue == domElement.value)
{
  //value is the same as original
}

The "_text" input is used when user type in it. And it shows formatted value(or empty message) when the RadTextBox is not in focus. The input without suffix in it's ID (in your example "yourtextbox") is used for submitting and validating. So none of this hold's the original value as properties. However as I wrote above you could use the DOM element of the "yourtextbox" to access it's defaultValue (which is the original one).

Greetings,
Vasil
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Andy
Top achievements
Rank 1
answered on 25 Aug 2011, 02:35 PM
Thanks Vasil, this information was most helpful.  The act of prompting a user to save any changes they have made before moving to another screen, or just limiting postbacks to happen only when fields have changed is a frequent requirement in computer systems.  We've had several people here try to implement their own methods of checking if fields were dirty, and this has resulted in an inconsistent approach.

I couldn't find this approach anywhere in the Telerik documentation.   It would be good if it was included in future releases of such documentation.
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Andy
Top achievements
Rank 1
Share this question
or