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

IsDirty - Ajax Dirty Panel

20 Answers 288 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 10 Dec 2008, 06:36 PM
Hi..
Does anyone have code that will implement a 'DirtyPanel' and prevent users from navigating away from a page and not saving thier changes?
I have seen examples using the AjaxToolKit and ASP.Net... but it doesn't work with the Telerik controls.
Any ideas how I can create a Telerik IsDirty Panel????

thanks in advance

20 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 15 Dec 2008, 12:00 PM
Hello Jon The Nerd,

For your convenience I've prepared sample application which imitates "DirtyPanel" behavior.
You can find sample application attached to this post. Please review the code.

I hope this is helpful.

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jon
Top achievements
Rank 1
answered on 22 Dec 2008, 02:20 PM
Thanks!!!!!!!!!!!!!!!!   You guys are great....

I changed it to use the RadTextBox....  How can I include the RadCombo and RadGrids on my page?

RadAjaxPanel1.Controls.OfType<

RadTextBox>().Select

 

0
Jon
Top achievements
Rank 1
answered on 22 Dec 2008, 03:28 PM
Hi..
One thing...
I have RadCombo on the page too...

As soon as I select a radcombo and change the value and try to navigate off the the page - It allows me... !
If I just just change radtextboxes and try and nagivate off I receilve the message..

What's the difference..???.. thanks again
0
Nikolay Rusev
Telerik team
answered on 22 Dec 2008, 05:04 PM
Hello Jon The Nerd,

Attached to this post you will find example how to handle RadTextBox and RadComboBox in "DirtyPanel" implementation.

I hope this is helpful.

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jon
Top achievements
Rank 1
answered on 22 Dec 2008, 06:32 PM
Hi.. Something is not working right....  I have 16 controls but when it runs it steps into 8 and jumps to the new page... 
It never checks the 

case "RadComboBox":

 


Any ideas... I can't find what wrong with the logic... thanks again


 

<telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">

 

 

<script type="text/javascript">

 

window.onbeforeunload =

function(e) {

 

 

if (IsDirty() == true) {

 

 

var ev = e || window.event;

 

ev.returnValue =

"Are you sure?";

 

}

}

 

function IsDirty() {

 

 

if (controls == null)

 

 

return false;

 

 

for (var i = 0, j = controls.length; i < j; i++) {

 

 

var control;

 

 

switch (controls[i].Type) {

 

 

case "TextBox":

 

control = $get(controls[i].ID);

 

if (control.value != controls[i].Value)

 

 

return true;

 

 

break;

 

 

case "RadTextBox":

 

control = $find(controls[i].ID);

 

if (control.GetValue() != controls[i].Value)

 

 

return true;

 

 

break;

 

 

case "RadComboBox":

 

control = $find(controls[i].ID);

 

if (control.get_selectedIndex() != controls[i].Value)

 

 

return true;

 

 

break;

 

}

}

 

return false;

 

}

 

</script>

 

 

</telerik:RadScriptBlock>

 

0
Nikolay Rusev
Telerik team
answered on 23 Dec 2008, 10:39 AM
Hi Jon The Nerd,

It seems to be working properly on my end.
Please check the code once again and ensure that you are using latest version of RadControls for ASP.NET AJAX.

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jon
Top achievements
Rank 1
answered on 23 Dec 2008, 02:25 PM
Hi..
I have 16 controls on my page... It loops through 8 and then goes to the next page... It only checks the first 8.  I can't figure out why it loops through 8 controls and then navigates to the next page  ?????????????????????    thanks for your help

for

 

(var i = 0, j = controls.length; i < j; i++) {

 

 

var control;

 

 

switch (controls[i].Type) {

 

 

case "RadComboBox":

 

control = $find(controls[i].ID);

 

if (control.get_selectedIndex() != controls[i].Value)

 

 

return true;

 

 

break;

 

 

case "TextBox":

 

control = $get(controls[i].ID);

 

if (control.value != controls[i].Value)

 

 

return true;

 

 

break;

 

 

case "RadTextBox":

 

control = $find(controls[i].ID);

 

if (control.GetValue() != controls[i].Value)

 

 

return true;

 

 

break;

 

 

}

}

0
Jon
Top achievements
Rank 1
answered on 23 Dec 2008, 04:08 PM
Hi..
Found the issue.
If you have hidden controls on the form - they are not found and the 'loop'  breaks - only checking a few controls before the
page 'closes'.  Also how can I include grids in the check?
thanks again!!!!!!
0
Jon
Top achievements
Rank 1
answered on 25 Dec 2008, 03:37 PM
Hi again
Also how can I include grids in the check? 
thanks again!!!!!!
0
Nikolay Rusev
Telerik team
answered on 29 Dec 2008, 12:07 PM
Hi Jon The Nerd,

Please find the attached project.
It demonstrates how to add support for hierarchy index of RadGrid selected item.
It is implemented similar to the other controls.

Greetings,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jon
Top achievements
Rank 1
answered on 29 Dec 2008, 08:10 PM
HI..
I'm getting an error  on

control[

"Value"] = ((GridDataItem)t.SelectedItems[0]).ItemIndexHierarchical;

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Any ideas ? 

thanks again!

 

0
Jon
Top achievements
Rank 1
answered on 29 Dec 2008, 09:08 PM
Hi.. again..
What if I just want to check if the data bound to the grid has been changed.
I don't use the grid by selecting rows or items.. just by changing values.
Thanks again!!!!!!!!!!!!!!!!!!
0
Hilton
Top achievements
Rank 1
answered on 10 Sep 2012, 05:07 PM
I know this post is old but I am trying to do something similar and downloaded the example DirtyPanel.zip. It works great in IE but not in Safari or Firefox. It seems that in the window.onbeforeunload function, "returnvalue" only works in IE, other browsers use "return" but that isn't the major problem here. What I am having a problem is in FireFox and Safari, any controls inside of the update panel will not post back to the server after the user clicks the cancel button to stay on the page.Any ideas?

For example, if you have a asp:button control inside of a telerik:RadAjaxPanel or a asp:UpdatePanel for that matter, the button will not postback to the server. Try the example inside of the DirtyPanel.zip example and add a button server control and place something inside of the server side event and test in Safari or Firefox and nothing will happen. Thanks in advance for any help or guidance that you may be able to supply.
0
Hilton
Top achievements
Rank 1
answered on 10 Sep 2012, 05:07 PM
I know this post is old but I am trying to do something similar and downloaded the example DirtyPanel.zip. It works great in IE but not in Safari or Firefox. It seems that in the window.onbeforeunload function, "returnvalue" only works in IE, other browsers use "return" but that isn't the major problem here. What I am having a problem is in FireFox and Safari, any controls inside of the update panel will not post back to the server after the user clicks the cancel button to stay on the page.Any ideas?

For example, if you have a asp:button control inside of a telerik:RadAjaxPanel or a asp:UpdatePanel for that matter, the button will not postback to the server. Try the example inside of the DirtyPanel.zip example and add a button server control and place something inside of the server side event and test in Safari or Firefox and nothing will happen. Thanks in advance for any help or guidance that you may be able to supply.
0
Antonio Stoilkov
Telerik team
answered on 13 Sep 2012, 10:29 AM
Hello,

I have tried to replicate the described issue but to no avail. I have defined a ASP Button control inside the RadAjaxPanel. You could take a look at the attached project in order to observe if there are any differences at your end. Additionally, I have created a video showing the behavior on my side in Firefox.

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Hilton
Top achievements
Rank 1
answered on 13 Sep 2012, 01:43 PM
Thanks Antonio for the reply. Hmmm, interesting, the only thing I see different in your implementation and mine is that I use master pages. I wonder if it is something else in my project causing it. I have a few 3rd party JQuery libraries that I am using in my master page. Maybe I need to take them out and see if that solves the problem. Thanks for confirming that it works in FireFox. :-)
0
Hilton
Top achievements
Rank 1
answered on 29 Sep 2012, 10:15 PM
I have another issue with using the example code for the DirtyPanel. In the SerializeControlProperties() method, the JavaScriptSerializer() doesn't seem to work well with a RadEditor when it contains lengthy html. The JavaScriptSerializer modifies the value in control["Value"] so even if you don't change the RadEditor's contents it will prompt you to save changes. Is there any kind of "work around" for this?

public static void SerializeControlProperties(Page MyPage, RadAjaxPanel RadAjaxPanel1)
        {
            Dictionary<string, string> control;
            List<Dictionary<string, string>> controlsCollection = new List<Dictionary<string, string>>(); ;
 
// other controls to check .....
 
            RadAjaxPanel1.Controls.OfType<RadEditor>().Select
            (
                  t =>
                  {
                      control = new Dictionary<string, string>();
                      control["ID"] = t.ClientID;
                      control["Type"] = "RadEditor";
                      control["Value"] = t.Content;
                      controlsCollection.Add(control);
                      return controlsCollection;
                  }
              ).Count();
 
            StringBuilder json = new StringBuilder();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            jss.Serialize(controlsCollection, json);
            //json.Append(controlsCollection.ToArray());
            json.Insert(0, "var controls = ");
            json.Append(";");
 
            ScriptManager.RegisterClientScriptBlock(MyPage.Page, typeof(Page), "MyKey", json.ToString(), true);
        }

and in the javascript IsDirty() function
case "RadEditor":
                control = $find(controls[i].ID);
                var newVal = control.get_html(true);
                var oldVal = controls[i].Value;
                // even if you make no changes it will not match
                if (newVal != oldVal)
                    return true;
                break;

0
Antonio Stoilkov
Telerik team
answered on 03 Oct 2012, 08:24 AM
Hello,

The described issue is caused by the maxJsonLenght property which limits the number of characters which could be transferred between the server and the client. You could resolve your issue by configuring the property as shown in the article below.

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Anna
Top achievements
Rank 2
answered on 25 Jan 2016, 06:03 AM
Was the masterpage problem ever resolved? I am having the same issue.  The javascript finds the controls and the values just fine.  The window.onbeforeunload doesn't seem to fire in Firefox or IE.
0
Maria Ilieva
Telerik team
answered on 27 Jan 2016, 01:32 PM
Hi Anna,

As the current thread is rather old I would suggest you to open a separate thread for your case and provide as much information as possible for the current state of the issue you are facing and for how it can be replicated. Thus we will be able to investigate it locally and advise you further.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Ajax
Asked by
Jon
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jon
Top achievements
Rank 1
Hilton
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Anna
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or