IsDirty - Ajax Dirty Panel

21 posts, 0 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 10 Dec 2008 Link to this post

    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

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 15 Dec 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 22 Dec 2008 Link to this post

    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

     

  5. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 22 Dec 2008 Link to this post

    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
  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 22 Dec 2008 Link to this post

    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.
  7. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 22 Dec 2008 Link to this post

    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>

     

  8. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 23 Dec 2008 Link to this post

    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.
  9. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 23 Dec 2008 Link to this post

    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;

     

     

    }

    }

  10. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 23 Dec 2008 Link to this post

    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!!!!!!
  11. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 25 Dec 2008 Link to this post

    Hi again
    Also how can I include grids in the check? 
    thanks again!!!!!!
  12. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 29 Dec 2008 Link to this post

    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.
  13. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 29 Dec 2008 Link to this post

    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!

     

  14. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 29 Dec 2008 Link to this post

    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!!!!!!!!!!!!!!!!!!
  15. Hilton
    Hilton avatar
    7 posts
    Member since:
    Aug 2012

    Posted 10 Sep 2012 Link to this post

    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.
  16. Hilton
    Hilton avatar
    7 posts
    Member since:
    Aug 2012

    Posted 10 Sep 2012 Link to this post

    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.
  17. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 13 Sep 2012 Link to this post

    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.
  18. Hilton
    Hilton avatar
    7 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2012 Link to this post

    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. :-)
  19. Hilton
    Hilton avatar
    7 posts
    Member since:
    Aug 2012

    Posted 29 Sep 2012 Link to this post

    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;

  20. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 03 Oct 2012 Link to this post

    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.
  21. Anna
    Anna avatar
    10 posts
    Member since:
    Dec 2010

    Posted 25 Jan in reply to Hilton Link to this post

    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.
  22. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 Jan Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017