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

[Solved] javascript confirm on RadGrid

1 Answer 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 01 May 2009, 02:55 PM
I'm working to update an existing application.  Currently when you do a rowClick on a RadGrid, the application will update another control.  I'd like to add a javascript confirm to that so, if the other control has changed, the user is reminded to save or cancel their changes.  However, regardless of what I pick on the confirm, the postback always occurs.  I assume that the javascript built in to the control runs after my confirm and still does the postback regardless of what I say. Is there a way I can keep the postback from occuring if the confirm returns false?


String getConfirmScript = "function getConfirm() { if (document.getElementsByName('_isUpdated').Value == '1') { if(!confirm('You changes have not been saved. Do you want to continue?')) { return false; } } }";

 

cm.RegisterClientScriptBlock(this.GetType(), "getConfirm", getConfirmScript, true);

 

 

_riskGrid =

new RadGrid();

 

 

 _riskGrid.EnableViewState =

true;

 

 

 _riskGrid.AutoGenerateColumns =

false;

 

 

 _riskGrid.Width =

Unit.Pixel(300);

 

 

 

//_riskGrid.Attributes.Add("onclick", "if (document.getElementsByName('_isUpdated').Value == '1') { return confirm('You changes have not been saved. Do you want to continue?'); }");

 

 

 

_riskGrid.AllowPaging = false;

 

 

 _riskGrid.AllowSorting =

false;

 

 

 

_riskGrid.ClientSettings.ClientEvents.OnRowClick =

"getConfirm";

Thanks,
Matt


 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 05 May 2009, 01:59 PM

Hello Matt,

You implementation for the client confirm script registration (provided that cm is the asp ScriptManager on the page) seems correct. Is it possible that you set ClientSettings -> EnablePostBackOnRowClick = true for the grid in this case? If so, note that the OnRowClick event of the control is not cancellable and the postback will occur regardless whether the confirmation dialog returns true or false value.

If this is the case, you may consider setting ClientSettings -> EnablePostBackOnRowClick = false, ajaxify the grid via RadAjaxManager (marking the manager as an initiator and the grid as an updated control) and trigger the refresh through the ajaxRequest(args) client method of the manager. Thus you will be able to control when form submit will be initiated based on the returned confirmation dialog value.

Best regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or