ASP.NET Use Javascript to Stop CodeBehind CallHow do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?How do I return the response from an asynchronous call?

Method Does Not Exist error message

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Unlock My Phone! February 2018

Forgetting the musical notes while performing in concert

Is it possible to create a QR code using text?

Can the Meissner effect explain very large floating structures?

Extract rows of a table, that include less than x NULLs

How much of data wrangling is a data scientist's job?

How badly should I try to prevent a user from XSSing themselves?

What killed these X2 caps?

ssTTsSTtRrriinInnnnNNNIiinngg

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Which is the best way to check return result?

Is it logically or scientifically possible to artificially send energy to the body?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Why didn't Miles's spider sense work before?

Can compressed videos be decoded back to their uncompresed original format?

What type of content (depth/breadth) is expected for a short presentation for Asst Professor interview in the UK?

Alternative to sending password over mail?

Assassin's bullet with mercury

Mathematica command that allows it to read my intentions

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?

What does the expression "A Mann!" means

Is "remove commented out code" correct English?



ASP.NET Use Javascript to Stop CodeBehind Call


How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?How do I return the response from an asynchronous call?













0















I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?



function ShowLoading() 



<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>









share|improve this question




























    0















    I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?



    function ShowLoading() 



    <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>









    share|improve this question


























      0












      0








      0








      I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?



      function ShowLoading() 



      <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>









      share|improve this question
















      I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?



      function ShowLoading() 



      <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>






      javascript asp.net






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 21:42









      omikes

      3,65682342




      3,65682342










      asked Mar 8 at 20:48









      John DoeJohn Doe

      76482144




      76482144






















          3 Answers
          3






          active

          oldest

          votes


















          1














          Remove onchange from DropDownList



          <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>


          And override generated onchange handler like this



          //make sure this code is executed when page is loaded
          <script>
          var dropdown = document.getElementById("dropDownMonth");
          var onchange = dropdown.onchange;
          dropdown.removeAttribute("onchange"); //removing original onchange handler
          var newonchange = function (ev)
          if (ShowLoading())
          onchange(ev);


          dropdown.onchange = newonchange;

          function ShowLoading()
          var postBack = /*condition to postback*/;
          //..
          return postBack;



          </script>





          share|improve this answer

























          • this doesn't work

            – John Doe
            Mar 8 at 21:46











          • alright close enough....i wrapped it in pageLoad method

            – John Doe
            Mar 8 at 22:10






          • 1





            @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

            – Alexander
            Mar 8 at 22:32


















          0














          Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.






          share|improve this answer























          • that doesn't work

            – John Doe
            Mar 8 at 21:18











          • function ShowLoading() return false;

            – John Doe
            Mar 8 at 21:26











          • Alexander's method of capturing and removing the existing onchange method looks like it should work.

            – Noah B
            Mar 8 at 21:45











          • it doesn't work...could it have something to do with it being in an updatepanel?

            – John Doe
            Mar 8 at 21:47






          • 1





            I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

            – Noah B
            Mar 8 at 21:55


















          0














          return false if you don't want to execute server side code (code behind)



          function ShowLoading() 

          // return true; // Will continue to call code behind

          return false; // Stop and don't call code behind



          and use return when calling the JS function onchange="return ShowLoading()"



          <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
          </asp:DropDownList>





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070783%2fasp-net-use-javascript-to-stop-codebehind-call%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Remove onchange from DropDownList



            <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>


            And override generated onchange handler like this



            //make sure this code is executed when page is loaded
            <script>
            var dropdown = document.getElementById("dropDownMonth");
            var onchange = dropdown.onchange;
            dropdown.removeAttribute("onchange"); //removing original onchange handler
            var newonchange = function (ev)
            if (ShowLoading())
            onchange(ev);


            dropdown.onchange = newonchange;

            function ShowLoading()
            var postBack = /*condition to postback*/;
            //..
            return postBack;



            </script>





            share|improve this answer

























            • this doesn't work

              – John Doe
              Mar 8 at 21:46











            • alright close enough....i wrapped it in pageLoad method

              – John Doe
              Mar 8 at 22:10






            • 1





              @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

              – Alexander
              Mar 8 at 22:32















            1














            Remove onchange from DropDownList



            <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>


            And override generated onchange handler like this



            //make sure this code is executed when page is loaded
            <script>
            var dropdown = document.getElementById("dropDownMonth");
            var onchange = dropdown.onchange;
            dropdown.removeAttribute("onchange"); //removing original onchange handler
            var newonchange = function (ev)
            if (ShowLoading())
            onchange(ev);


            dropdown.onchange = newonchange;

            function ShowLoading()
            var postBack = /*condition to postback*/;
            //..
            return postBack;



            </script>





            share|improve this answer

























            • this doesn't work

              – John Doe
              Mar 8 at 21:46











            • alright close enough....i wrapped it in pageLoad method

              – John Doe
              Mar 8 at 22:10






            • 1





              @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

              – Alexander
              Mar 8 at 22:32













            1












            1








            1







            Remove onchange from DropDownList



            <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>


            And override generated onchange handler like this



            //make sure this code is executed when page is loaded
            <script>
            var dropdown = document.getElementById("dropDownMonth");
            var onchange = dropdown.onchange;
            dropdown.removeAttribute("onchange"); //removing original onchange handler
            var newonchange = function (ev)
            if (ShowLoading())
            onchange(ev);


            dropdown.onchange = newonchange;

            function ShowLoading()
            var postBack = /*condition to postback*/;
            //..
            return postBack;



            </script>





            share|improve this answer















            Remove onchange from DropDownList



            <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>


            And override generated onchange handler like this



            //make sure this code is executed when page is loaded
            <script>
            var dropdown = document.getElementById("dropDownMonth");
            var onchange = dropdown.onchange;
            dropdown.removeAttribute("onchange"); //removing original onchange handler
            var newonchange = function (ev)
            if (ShowLoading())
            onchange(ev);


            dropdown.onchange = newonchange;

            function ShowLoading()
            var postBack = /*condition to postback*/;
            //..
            return postBack;



            </script>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 8 at 22:44

























            answered Mar 8 at 21:32









            AlexanderAlexander

            3,1321521




            3,1321521












            • this doesn't work

              – John Doe
              Mar 8 at 21:46











            • alright close enough....i wrapped it in pageLoad method

              – John Doe
              Mar 8 at 22:10






            • 1





              @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

              – Alexander
              Mar 8 at 22:32

















            • this doesn't work

              – John Doe
              Mar 8 at 21:46











            • alright close enough....i wrapped it in pageLoad method

              – John Doe
              Mar 8 at 22:10






            • 1





              @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

              – Alexander
              Mar 8 at 22:32
















            this doesn't work

            – John Doe
            Mar 8 at 21:46





            this doesn't work

            – John Doe
            Mar 8 at 21:46













            alright close enough....i wrapped it in pageLoad method

            – John Doe
            Mar 8 at 22:10





            alright close enough....i wrapped it in pageLoad method

            – John Doe
            Mar 8 at 22:10




            1




            1





            @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

            – Alexander
            Mar 8 at 22:32





            @JohnDoe one thing I forgot to include in my answer, you have to remove onchange="ShowLoading()" code from element

            – Alexander
            Mar 8 at 22:32













            0














            Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.






            share|improve this answer























            • that doesn't work

              – John Doe
              Mar 8 at 21:18











            • function ShowLoading() return false;

              – John Doe
              Mar 8 at 21:26











            • Alexander's method of capturing and removing the existing onchange method looks like it should work.

              – Noah B
              Mar 8 at 21:45











            • it doesn't work...could it have something to do with it being in an updatepanel?

              – John Doe
              Mar 8 at 21:47






            • 1





              I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

              – Noah B
              Mar 8 at 21:55















            0














            Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.






            share|improve this answer























            • that doesn't work

              – John Doe
              Mar 8 at 21:18











            • function ShowLoading() return false;

              – John Doe
              Mar 8 at 21:26











            • Alexander's method of capturing and removing the existing onchange method looks like it should work.

              – Noah B
              Mar 8 at 21:45











            • it doesn't work...could it have something to do with it being in an updatepanel?

              – John Doe
              Mar 8 at 21:47






            • 1





              I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

              – Noah B
              Mar 8 at 21:55













            0












            0








            0







            Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.






            share|improve this answer













            Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 21:04









            Noah BNoah B

            1335




            1335












            • that doesn't work

              – John Doe
              Mar 8 at 21:18











            • function ShowLoading() return false;

              – John Doe
              Mar 8 at 21:26











            • Alexander's method of capturing and removing the existing onchange method looks like it should work.

              – Noah B
              Mar 8 at 21:45











            • it doesn't work...could it have something to do with it being in an updatepanel?

              – John Doe
              Mar 8 at 21:47






            • 1





              I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

              – Noah B
              Mar 8 at 21:55

















            • that doesn't work

              – John Doe
              Mar 8 at 21:18











            • function ShowLoading() return false;

              – John Doe
              Mar 8 at 21:26











            • Alexander's method of capturing and removing the existing onchange method looks like it should work.

              – Noah B
              Mar 8 at 21:45











            • it doesn't work...could it have something to do with it being in an updatepanel?

              – John Doe
              Mar 8 at 21:47






            • 1





              I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

              – Noah B
              Mar 8 at 21:55
















            that doesn't work

            – John Doe
            Mar 8 at 21:18





            that doesn't work

            – John Doe
            Mar 8 at 21:18













            function ShowLoading() return false;

            – John Doe
            Mar 8 at 21:26





            function ShowLoading() return false;

            – John Doe
            Mar 8 at 21:26













            Alexander's method of capturing and removing the existing onchange method looks like it should work.

            – Noah B
            Mar 8 at 21:45





            Alexander's method of capturing and removing the existing onchange method looks like it should work.

            – Noah B
            Mar 8 at 21:45













            it doesn't work...could it have something to do with it being in an updatepanel?

            – John Doe
            Mar 8 at 21:47





            it doesn't work...could it have something to do with it being in an updatepanel?

            – John Doe
            Mar 8 at 21:47




            1




            1





            I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

            – Noah B
            Mar 8 at 21:55





            I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.

            – Noah B
            Mar 8 at 21:55











            0














            return false if you don't want to execute server side code (code behind)



            function ShowLoading() 

            // return true; // Will continue to call code behind

            return false; // Stop and don't call code behind



            and use return when calling the JS function onchange="return ShowLoading()"



            <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
            </asp:DropDownList>





            share|improve this answer





























              0














              return false if you don't want to execute server side code (code behind)



              function ShowLoading() 

              // return true; // Will continue to call code behind

              return false; // Stop and don't call code behind



              and use return when calling the JS function onchange="return ShowLoading()"



              <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
              </asp:DropDownList>





              share|improve this answer



























                0












                0








                0







                return false if you don't want to execute server side code (code behind)



                function ShowLoading() 

                // return true; // Will continue to call code behind

                return false; // Stop and don't call code behind



                and use return when calling the JS function onchange="return ShowLoading()"



                <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
                </asp:DropDownList>





                share|improve this answer















                return false if you don't want to execute server side code (code behind)



                function ShowLoading() 

                // return true; // Will continue to call code behind

                return false; // Stop and don't call code behind



                and use return when calling the JS function onchange="return ShowLoading()"



                <asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
                </asp:DropDownList>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 8 at 22:26

























                answered Mar 8 at 22:00









                ElasticCodeElasticCode

                2,98611023




                2,98611023



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070783%2fasp-net-use-javascript-to-stop-codebehind-call%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229