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

RadWindow Unsaved Changes

2 Answers 151 Views
Window
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 1
Michele asked on 21 Aug 2012, 03:33 PM
I am using Telerik ASP.NET AJAX Version 2012.1.411.40.  I have a page  where the user enters some search criteria and the search results are returned and displayed in a radGrid on the page.  If the entry in the grid is editable, an edit pencil is displayed. When the user clicks the edit pencil, a custom edit form is displayed in a radWindow. This window is opened from the codebehind (I need to pass several values to the edit form so that I know which record I need to edit) in the OnClick event handler using the following code:

rwinEditCustomer.Modal =

 

true;

 

rwinEditCustomer.NavigateUrl =

 

String.Format("CustomerAddEdit.aspx?source={0}&addrid={1}&cntctid={2}", lblSource.Text, hdnAddressId.Value, hdnContactId.Value);

 

 

 

string script = "function f(){$find(\"" + rwinEditCustomer.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

 

 

 

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "winEditCust", script, true);

 


Buttons are available on the edit form for the user to delete the entry, save the information, or cancel.  If the user clicks delete, I use radconfirm to display a confirmation message. If the user choses to continue with the delete, the record is deleted, the radwindow is closed and the radgrid is rebound. If the user clicks save, the information is saved, the radwindow is closed and the radgrid is rebound.  If the user clicks cancel, the radwindow is closed. That all seems to be working. Now  I need to detect if the user changed any information. If data has been changed, I need to use radconfirm to warn the user about unsaved changes if they click cancel or try to close the edit window. I don't want to warn the user if they click save or if they close the edit window without changing any information.  I've searched through the forums for guidance but haven't been able to connect the dots to get this to work the way I need it to.  At one point, I had it working where I got a valid unsaved changes warning (not using radconfirm though) when the cancel was clicked. But when I tried to close the edit window, the radwindow closed and then displayed the warning which is not the order I'm looking for. 

Any suggestions on how I can do this?

Thanks

2 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 22 Aug 2012, 12:35 PM
Hello Michele,

One approach would be to add a hidden field to your RadWindow page that would be used to determine if the RadWindow should be prevented from closing. Then you can handle the OnClientBeforeClose event and check the hidden field to determine if the RadWindow should close.

So something like so:

function OnClientBeforeClose(sender, args) {
    var hdnPreventClose = $get("hdnPreventClose", sender.get_contentFrame());
      
    if (hdnPreventClose.value == "true") {
        args.set_cancel(true);
    }

I would suggest using a standard html hidden field, instead of an asp:HiddenFIeld, so that you can find the control easier since the ID will be simpler to add.

Also, in your RadWindow, you can then call the RadConfirm and during it's callback method, you can update the hidden field by passing "false" and then close the window if the user does not want to save the changes.

I hope that helps.
0
Michele
Top achievements
Rank 1
answered on 22 Aug 2012, 04:55 PM
Thanks so much for the suggestion. I will try it out as soon as I can and let you what happened. I was switched to another project so I may not get to try this until next week.  Thanks again.
Tags
Window
Asked by
Michele
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Michele
Top achievements
Rank 1
Share this question
or