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

Radgrid - Problem while performing sort by columns

6 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ELBU
Top achievements
Rank 1
ELBU asked on 25 Nov 2008, 12:30 PM

Hi,
I'm trying to do the following :
If the user decides to press x of the Explorer (close)  , while running my web application , I added a message asking is he sure
want to do it.

But my problem was that each button pressed on screen , caused this message to apper.

So , what I did is wrote the following functions and used them in order to prevent appearance of the message

In each button that appears on the page i added event :

 

OnClientClick

="javascript:ToggleBeforeUnload();"

 

 

BUT WHEN I'M TRYING TO SORT COLUMNS IN GRID , I STILL GET THE MESSAGE  :(

I need your advise please on which even I must run  ToggleBeforeUnload() or is there another solution ?

Thanks a lot !


--------- The functions I've wrote -------------

var

suppressWarningMsg = false;

 

 

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

 

 

function BeginRequestHandler(sender, eventArgs)

 

{

    suppressWarningMsg =

true;

 

}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

 

 


function
EndRequestHandler(sender, eventArgs)

 

{

suppressWarningMsg =

false;

 

}

 

 

function ConfirmExit()

 

{

 

        if (!suppressWarningMsg)

 

       {

 

                  return 'SURE WANNA EXIT ?;

 

       }

}

 

window.onbeforeunload = ConfirmExit;

 

var onOff = false;

 

 

 

function ToggleBeforeUnload(onOff)

 

{

 

 

if (onOff == true)

 

{

window.onbeforeunload = ConfirmExit;

// Activate beforeunload event handler

 

}

 

else

 

{

window.onbeforeunload =

null;

 

}

}

6 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 25 Nov 2008, 01:11 PM
Hello ELBU,

Generally onbeforeunload will be raised on every "javascript:somefunction()" - like the default LinkButtons in the grid header for sorting. You can avoid this if you set HeaderButtonType="TextButton" for desired grid columns.


All the best,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ELBU
Top achievements
Rank 1
answered on 25 Nov 2008, 01:18 PM
thanks a lot ,
it helped :)
0
Lenny_shp
Top achievements
Rank 2
answered on 04 Dec 2008, 08:55 PM
How do I make use of onBeforeUnload in situation where filter is enabled or other CommandItemTemplate items exist?   They still pop those up.

Naturally I want to check if there are actually any data changes (from ItemCommand which I can check against values of InPlace edit items).
0
Rosen
Telerik team
answered on 05 Dec 2008, 09:19 AM
Hello Lenny,

You may try hooking to RadGrid's client-side Command event and set a flag to cancel the showing of the message, similar to the following:

<script type="text/javascript">  
                var shouldShowMsg = true;  
                window.onbeforeunload = function (){ if(shouldShowMsg) return "Are you sure?"};  
                  
                function onCommand(sender, args)  
                {  
                    shouldShowMsg = false;  
                }  
            </script> 
              
            <telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="SqlDataSource1" GridLines="None" 
                AllowSorting="true" AllowFilteringByColumn="true" AllowPaging="true" PageSize="3">                  
                <ClientSettings> 
                    <ClientEvents OnCommand="onCommand" /> 
                </ClientSettings> 
                <!-- ... --> 
            </telerik:RadGrid> 

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Lenny_shp
Top achievements
Rank 2
answered on 05 Dec 2008, 05:08 PM
After AJAX grid function, shouldShowMsg becomes permanently false and I can exit the browser w/o the warning.
When does shouldShowMsg get set back to true again?


0
Rosen
Telerik team
answered on 08 Dec 2008, 12:34 PM
Hello Lenny,

When using ajax you can output the shouldShowMsg variable's declaration on every request by register it through the ScriptManager's instance. similar to the following:

    protected void Page_Load(object sender, EventArgs e)  
    {  
        ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "submitFlag""var shouldShowMsg = true;"true);  
    } 

This way when the page is submitted the variable will be reset to its initial value.

All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
ELBU
Top achievements
Rank 1
Answers by
Vlad
Telerik team
ELBU
Top achievements
Rank 1
Lenny_shp
Top achievements
Rank 2
Rosen
Telerik team
Share this question
or