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. java script problem while using in web application.

java script problem while using in web application.

Scheduled Pinned Locked Moved Web Development
helpjavajavascriptsysadmintools
8 Posts 3 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.
  • S Offline
    S Offline
    susree
    wrote on last edited by
    #1

    Hi , I am using javascript for confirm dialog box in my web application. I want to do some server side execution and then if there is some error I want to display the confirm dialog box. but if I am adding it as button1.Attributes.Add("onClick", "return Confirm();"); on body load event .I am getting the message when ever I am clicking the button ,which I don't want . hope I explained my problem clearly. can any one help me out? thanks sangita

    T 1 Reply Last reply
    0
    • S susree

      Hi , I am using javascript for confirm dialog box in my web application. I want to do some server side execution and then if there is some error I want to display the confirm dialog box. but if I am adding it as button1.Attributes.Add("onClick", "return Confirm();"); on body load event .I am getting the message when ever I am clicking the button ,which I don't want . hope I explained my problem clearly. can any one help me out? thanks sangita

      T Offline
      T Offline
      theJazzyBrain
      wrote on last edited by
      #2

      So, if I understand correctly you want the javascript to be executed only if an error occurs on the server? What server side language are you using? theJazzyBrain Wise is he who asks good questions, not he who gives good answers

      S 1 Reply Last reply
      0
      • T theJazzyBrain

        So, if I understand correctly you want the javascript to be executed only if an error occurs on the server? What server side language are you using? theJazzyBrain Wise is he who asks good questions, not he who gives good answers

        S Offline
        S Offline
        susree
        wrote on last edited by
        #3

        yes that's what I want. I am using c# as server side language. thanks

        T 1 Reply Last reply
        0
        • S susree

          yes that's what I want. I am using c# as server side language. thanks

          T Offline
          T Offline
          theJazzyBrain
          wrote on last edited by
          #4

          The onlcick even that you set to that button will not give such functionality. You have to write the javascript on the client only if the server throws an exception. You will do that within the catch{} I hope that I helped you. theJazzyBrain Wise is he who asks good questions, not he who gives good answers

          H 1 Reply Last reply
          0
          • T theJazzyBrain

            The onlcick even that you set to that button will not give such functionality. You have to write the javascript on the client only if the server throws an exception. You will do that within the catch{} I hope that I helped you. theJazzyBrain Wise is he who asks good questions, not he who gives good answers

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            Right, you can't intermix server- and client-side code like the original poster wants, but you can tell the server-side code to emit code like that, either by output the code directly or using the Page.RegisterStartupScript method with, like so:

            try
            {
            throw new Exception();
            }
            catch (Exception ex)
            {
            string script = string.Format(
            "<script language=\"javascript\">alert('{0}');</script>",
            ex.Message);
            RegisterStartupScript("myUniqueKey1", script);
            }

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            S 1 Reply Last reply
            0
            • H Heath Stewart

              Right, you can't intermix server- and client-side code like the original poster wants, but you can tell the server-side code to emit code like that, either by output the code directly or using the Page.RegisterStartupScript method with, like so:

              try
              {
              throw new Exception();
              }
              catch (Exception ex)
              {
              string script = string.Format(
              "<script language=\"javascript\">alert('{0}');</script>",
              ex.Message);
              RegisterStartupScript("myUniqueKey1", script);
              }

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              S Offline
              S Offline
              susree
              wrote on last edited by
              #6

              I have tried with using RegisterStartupScript("myUniqueKey1", script) method, what ever you have written but the alert message is not coming.It is only coming after refreshing the page(reloading the page). but I want to display the message before refreshing the page. I have tried with adding submit method in javascript ,but it is not working. can you suggest something? thanks

              H S 2 Replies Last reply
              0
              • S susree

                I have tried with using RegisterStartupScript("myUniqueKey1", script) method, what ever you have written but the alert message is not coming.It is only coming after refreshing the page(reloading the page). but I want to display the message before refreshing the page. I have tried with adding submit method in javascript ,but it is not working. can you suggest something? thanks

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                It matters where you do this. An older implementation of our application web site used to do this and I can assure you it works. If you add the startup script in your button.Click event handler (or after the appropriate logic in Page_Load) it can work, but you have to write the javascript right. If you right it as a function, something has to call that function. Otherwise, whichout a function "wrapper", the script is executed when it is encountered. Judging by your previous example, you put such code in a function and expected a client-side event on a button or something to fire it. You don't want to do that. If nothing else, at least make the onload event of the BODY call your function, but this would require that you either parse the HTML yourself (very bad!) or make the body a server control (but that's bad too, so just don't put such code in a method).

                -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                1 Reply Last reply
                0
                • S susree

                  I have tried with using RegisterStartupScript("myUniqueKey1", script) method, what ever you have written but the alert message is not coming.It is only coming after refreshing the page(reloading the page). but I want to display the message before refreshing the page. I have tried with adding submit method in javascript ,but it is not working. can you suggest something? thanks

                  S Offline
                  S Offline
                  susree
                  wrote on last edited by
                  #8

                  thanks a lot. now it is working fine.Only thing is that when ever I am trying to use the back button of browser it is showing the alert message .which I don't want. what I think is while using the back button we are reloading the page so the alert message is coming. can you suggest something to help me out? thanks.

                  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