Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Javascript confirmation in asp.net

Javascript confirmation in asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netannouncement
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nagraj Naik
    wrote on last edited by
    #1

    Hi, I have used javascript confirmation on button click.On button click confirmation message pop up correctly. I have "update()" and "addnew()" function calls in button click event,If user click button confirmation message should get pop up and on confirmation "update()" function should get called else "AddNew()" function should get called. I hope someone know solution plz share ur idea with me. Thanks, Nagraj.

    P 1 Reply Last reply
    0
    • N Nagraj Naik

      Hi, I have used javascript confirmation on button click.On button click confirmation message pop up correctly. I have "update()" and "addnew()" function calls in button click event,If user click button confirmation message should get pop up and on confirmation "update()" function should get called else "AddNew()" function should get called. I hope someone know solution plz share ur idea with me. Thanks, Nagraj.

      P Offline
      P Offline
      Prateek G
      wrote on last edited by
      #2

      Response.Write( "" + " function showAchPendingMsg() { " + " var pendingConfirmation = window.confirm('PG');" + " if (pendingConfirmation == true) { ShowDetail()"+ " } else { DoShow()"+ " " + " } " + " }" + " showAchPendingMsg();" + " function DoShow() { alert('else');}"+ " function ShowDetail() { alert('if');}"+ "<" + "/" + "script>"); </x-turndown>

      C 1 Reply Last reply
      0
      • P Prateek G

        Response.Write( "" + " function showAchPendingMsg() { " + " var pendingConfirmation = window.confirm('PG');" + " if (pendingConfirmation == true) { ShowDetail()"+ " } else { DoShow()"+ " " + " } " + " }" + " showAchPendingMsg();" + " function DoShow() { alert('else');}"+ " function ShowDetail() { alert('if');}"+ "<" + "/" + "script>"); </x-turndown>

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        RegisterClientScriptBlock is better, and you didn't show him how to hook the call into his click event, either.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        P 1 Reply Last reply
        0
        • C Christian Graus

          RegisterClientScriptBlock is better, and you didn't show him how to hook the call into his click event, either.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          P Offline
          P Offline
          Prateek G
          wrote on last edited by
          #4

          Is this the code wot u were talking about ? If yes will u plz lemme know why it is better? string scriptString =( "" + " function showAchPendingMsg() { " + " var pendingConfirmation = window.confirm('PG');" + " if (pendingConfirmation == true) { ShowDetail()"+ " } else { DoShow()"+ " " + " } " + " }" + " showAchPendingMsg();" + " function DoShow() { alert('else');}"+ " function ShowDetail() { alert('if');}"+ "<" + "/" + "script>"); string scriptName = "Confirm"; if(!Page.IsClientScriptBlockRegistered(scriptName);) { Page.RegisterClientScriptBlock(scriptName,scriptString); } </x-turndown>

          N 1 Reply Last reply
          0
          • P Prateek G

            Is this the code wot u were talking about ? If yes will u plz lemme know why it is better? string scriptString =( "" + " function showAchPendingMsg() { " + " var pendingConfirmation = window.confirm('PG');" + " if (pendingConfirmation == true) { ShowDetail()"+ " } else { DoShow()"+ " " + " } " + " }" + " showAchPendingMsg();" + " function DoShow() { alert('else');}"+ " function ShowDetail() { alert('if');}"+ "<" + "/" + "script>"); string scriptName = "Confirm"; if(!Page.IsClientScriptBlockRegistered(scriptName);) { Page.RegisterClientScriptBlock(scriptName,scriptString); } </x-turndown>

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            He is telling instead of using Response.Write to send JS script, use RegisterClientScript which is in page object.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            P 1 Reply Last reply
            0
            • N N a v a n e e t h

              He is telling instead of using Response.Write to send JS script, use RegisterClientScript which is in page object.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              P Offline
              P Offline
              Prateek G
              wrote on last edited by
              #6

              Yeah I understood.. But now I just want to know how it is better.. what is the utility of it.

              J 1 Reply Last reply
              0
              • P Prateek G

                Yeah I understood.. But now I just want to know how it is better.. what is the utility of it.

                J Offline
                J Offline
                John ph
                wrote on last edited by
                #7

                What did you exactly tried to do with the Response.Write method? Let me say that clearly - You tried to Register blocks of client-side script containing functions. Microsoft has provide a method very specific to perform this particular task 'RegisterClientScriptBlock'. Response.write Method is meant for writting a specified string to the current HTTP output. The specified string can be a Dynamically Build Javascript Code. But it's well suitable for a Javascript Alert message when we try to write Javascript code on the client using Response.Write(), Not for Registering blocks of client-side script containing functions. There are many ways to solve a problem. The question is Are we doing it the right way, the best way?

                - Regards -
                   JON


                Life is not measured by the amount of breaths we take, but by the moments that take our breath away.


                N 1 Reply Last reply
                0
                • J John ph

                  What did you exactly tried to do with the Response.Write method? Let me say that clearly - You tried to Register blocks of client-side script containing functions. Microsoft has provide a method very specific to perform this particular task 'RegisterClientScriptBlock'. Response.write Method is meant for writting a specified string to the current HTTP output. The specified string can be a Dynamically Build Javascript Code. But it's well suitable for a Javascript Alert message when we try to write Javascript code on the client using Response.Write(), Not for Registering blocks of client-side script containing functions. There are many ways to solve a problem. The question is Are we doing it the right way, the best way?

                  - Regards -
                     JON


                  Life is not measured by the amount of breaths we take, but by the moments that take our breath away.


                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #8

                  This is not the exact difference. Response.Write() places the string (in this case dynamic JS code) supplied on the top of the page, that is outside HTML tag. But using the specified methods to emit client script ensures that it is inside the DOM. You can use either RegisterClientScriptBlock() or RegisterStartupScript() for injecting JS code to the page. More over, RegisterStartupScript() executes before the page's OnLoad() event fires.

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                  P J 2 Replies Last reply
                  0
                  • N N a v a n e e t h

                    This is not the exact difference. Response.Write() places the string (in this case dynamic JS code) supplied on the top of the page, that is outside HTML tag. But using the specified methods to emit client script ensures that it is inside the DOM. You can use either RegisterClientScriptBlock() or RegisterStartupScript() for injecting JS code to the page. More over, RegisterStartupScript() executes before the page's OnLoad() event fires.

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                    P Offline
                    P Offline
                    Prateek G
                    wrote on last edited by
                    #9

                    Thanks!!! Thats wot I wanted to know, If I am doing something I should know why I am doing so...

                    1 Reply Last reply
                    0
                    • N N a v a n e e t h

                      This is not the exact difference. Response.Write() places the string (in this case dynamic JS code) supplied on the top of the page, that is outside HTML tag. But using the specified methods to emit client script ensures that it is inside the DOM. You can use either RegisterClientScriptBlock() or RegisterStartupScript() for injecting JS code to the page. More over, RegisterStartupScript() executes before the page's OnLoad() event fires.

                      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                      J Offline
                      J Offline
                      John ph
                      wrote on last edited by
                      #10

                      N a v a n e e t h wrote:

                      This is not the exact difference

                      Did I explain about the Differences? I guess No. I tried to compare with what Prateek did with Response.Write() and What Could have been done.

                      - Regards -
                         JON


                      Life is not measured by the amount of breaths we take, but by the moments that take our breath away.


                      N 1 Reply Last reply
                      0
                      • J John ph

                        N a v a n e e t h wrote:

                        This is not the exact difference

                        Did I explain about the Differences? I guess No. I tried to compare with what Prateek did with Response.Write() and What Could have been done.

                        - Regards -
                           JON


                        Life is not measured by the amount of breaths we take, but by the moments that take our breath away.


                        N Offline
                        N Offline
                        N a v a n e e t h
                        wrote on last edited by
                        #11

                        John Prabhu wrote:

                        Did I explain about the Differences?

                        He was asking about why use client script methods to register instead of Response.Write. But your answer was not fully explaining. So I guessed you were comparing Response.Write and the other and given my reply.

                        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups