Click here to Skip to main content
15,904,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
In my webpage, I show confirm message when I leave the page and navigate new page. It is working fine. But one of my page has treeview. On that page only every time I expand and collapse treeview It asks confirmation message. How we avoid it. Please help me, for this problem.
My coding is

XML
<script type="text/javascript" language="javascript">
       window.onbeforeunload = function () {
          
           if (document.getElementById("<%=hdnSavingMode.ClientID %>").value.toUpperCase() == 'TRUE') {
               return "Do you want to leave this page without saving?";

           }
       };
    </script>


It happens only IE not in firefox. I am using IE 8 version.
Posted
Updated 6-Mar-14 0:41am
v3
Comments
Krunal Rohit 6-Mar-14 2:03am    
Can you post your code ?

-KR
devausha 6-Mar-14 4:19am    
see my updated question

This is actually working correctly in IE8 and broken in Firefox. This event will fire every time page posts back, which is why you are seeing it when using the treeview. Firefox has a known issue where the returned text is not displayed to the user (Here[^], Here[^]). The correct way to use onbeforeunload for firefox is:

JavaScript
<script type="text/javascript" language="javascript">
       window.onbeforeunload = function (event) {
          
           if (document.getElementById("<%=hdnSavingMode.ClientID %>").value.toUpperCase() == 'TRUE') {
               if(event != null && typeof(event) != 'undefined')
                   event.returnValue = "Do you want to leave this page without saving?";
               return "Do you want to leave this page without saving?";
 
           }
       };
    </script>
 
Share this answer
 
v2
Comments
devausha 6-Mar-14 23:50pm    
It is not working in IE8 version. It shows an error like 'undefined' is null or not an object'.
In my case my code is working in Firefox not working in IE8
Shelby Robertson 6-Mar-14 23:57pm    
sorry i updated my solution to add a check for event being undefined.
devausha 7-Mar-14 0:09am    
Hi thank for your reply. I tried your updated solution. But still now the same issue is happenend in IE8. When I click the treeview node, it asks confirmation message.
Shelby Robertson 7-Mar-14 0:18am    
As i noted in my solution, that is what should happen when using the onbeforeunload event.
Hai

in ur treeview expand and collapse page hit the server,so in page onbeforeunload event fires,so try to avoid page refresh when expand or collapse treeview,so use update panel for treeview,it avoid page reload,

U have to move confirm message to server side button click event instead of client side or use client side button click event dont use window event,





ASP.NET
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                  <ContentTemplate>

                                  </ContentTemplate>
                              </asp:UpdatePanel>


in treeview expand and collapse u did in server side ?,try to expand and collapse form client. side


regards
Aravind
 
Share this answer
 
v3
Comments
devausha 7-Mar-14 0:41am    
Hi Aravind,
Thanks for your reply, I am using update panel, but same issue happens. my code is
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<contenttemplate>
<asp:TreeView ID="Menu1" runat="server" ImageSet="Arrows" ShowCheckBoxes="All">





And I don't how to call confirm message from server side. Can u help me.
Aravindba 7-Mar-14 1:01am    
how u leave current page and navigate to other page ? in which click event ?
devausha 7-Mar-14 1:49am    
I am not using event. If the user leave the page, if they close the page or other wise navigate new page, it will call automatically.
Aravindba 7-Mar-14 2:01am    
where u put redirect to other page ? or if click browser close ('X') button ?
devausha 7-Mar-14 3:17am    
click browser close button, otherwise I move one page to other page by clicking link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900