[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?

Stop popping up the save message when option buttion is clicked ASP.Net  VB.Net

Posted on 2017-10-12
7
High Priority
?
33 Views
Last Modified: 2017-10-18
Hi Experts,

This is my code to display the save message while exiting the form without saving. I know how to not show it when 'Save' button is clicked. But how can I stop it from popping up while any option button is clicked which has a postback.

Thanks in advance.


Option button code
----------------------------
<asp:RadioButton ID="rbMenuItems" runat="server" Text="Menu Items" class="RadioButtons" GroupName="grpRbMenu" AutoPostBack ="true"/>


<script src="js/jquery.min.js"></script>
    <script>
        var NoDirtyScreen = false;
        var Changes = false;
        function DirtyScreenHide() {
            NoDirtyScreen = true;
        }

        $(document).ready(function () {
            $("input[type='text']").change(function () {
                Changes = true;
            })

            $("select").on("click", function () {
                Changes = true;
            })
        });
       
        var unloadEvent = function (e) {
            if (!NoDirtyScreen && Changes) {
                var confirmationMessage = "Warning: Leaving this page will result in any unsaved data being lost. Are you sure you wish to continue?";

                (e || window.event).returnValue = confirmationMessage; //Gecko + IE
                return confirmationMessage; //Webkit, Safari, Chrome etc.
            };
        }
       
       window.addEventListener("beforeunload", unloadEvent);
       
</script>
0
Comment
Question by:RadhaKrishnaKiJaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Dorababu M
Change your unload function as follows

var v = $('input[id*=rbMenuItems]').is(":checked");
            if (!v && !NoDirtyScreen && Changes) {
                var confirmationMessage = "Warning: Leaving this page will result in any unsaved data being lost. Are you sure you wish to continue?";

                (e || window.event).returnValue = confirmationMessage; //Gecko + IE
                return confirmationMessage; //Webkit, Safari, Chrome etc.
            };

Open in new window

0
 

Author Comment

by:RadhaKrishnaKiJaya
Thank you for your reply. How can I check for all the radio buttons? because there are multiple.
0
 

Author Comment

by:RadhaKrishnaKiJaya
Also there is always one option button selected. So when I check for "Checked" it is returning me "true" all the time. Please suggest.

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:Dorababu M
You can try as below if your class is same for all radio buttons
$('RadioButtons').each(function(){
  if($(this).find('input[type="radio"]:checked').length > 0)
    {
       alert("checked");
    }
  else
    {
       alert("not checked");
    }    
});

Open in new window

0
 

Author Comment

by:RadhaKrishnaKiJaya
Hi,

Thanks for the reply. But it didn't work. Actually let me tell you the problem again. There are two option buttons on my page. Always one option button is checked. When I click the other option button, I am getting the popup "Save" message. Which I don't want. So some how I have to set a variable only when the option is changed or clicked. So that I can check it before displaying the save message.

Thanks.
0
 
LVL 6

Expert Comment

by:Dorababu M
What didn't worked? the radio buttons are of same group name some thing like this
 <asp:RadioButton Checked="true" ID="rbMenuItems" runat="server" Text="Menu Items" class="RadioButtons" GroupName="grpRbMenu" AutoPostBack="true" />
            <asp:RadioButton ID="RadioButton1" runat="server" Text="Menu Items" class="RadioButtons" GroupName="grpRbMenu" AutoPostBack="true" />

Open in new window

0
 

Author Comment

by:RadhaKrishnaKiJaya
Hi,

Thanks for the reply. I am using this code. But still I am getting the pop up message when I click the other option button.

 $('RadioButtons').each(function () {
            if ($(this).find('input[type="radio"]:checked').length > 0) {
                OptionButtonClicked = True;
            }
           
        });

unload event
----------------

 var unloadEvent = function (e) {
            if (!OptionButtonClicked && !OptionButtonClicked && !NoDirtyScreen) {
                var confirmationMessage = "Warning: Leaving this page will result in any unsaved data being lost. Are you sure you wish to continue?";

                (e || window.event).returnValue = confirmationMessage; //Gecko + IE
                return confirmationMessage; //Webkit, Safari, Chrome etc.
            };
        }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question