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. How to execute a javascript after a post back event occured??

How to execute a javascript after a post back event occured??

Scheduled Pinned Locked Moved ASP.NET
javascripthelptutorialquestion
8 Posts 4 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
    SIJUTHOMASP
    wrote on last edited by
    #1

    Hai, How I can execute a javascript after a post back event occured.Please help me by showing the right way... Thank You, Siju Thomas.

    E A S 3 Replies Last reply
    0
    • S SIJUTHOMASP

      Hai, How I can execute a javascript after a post back event occured.Please help me by showing the right way... Thank You, Siju Thomas.

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      Hi there, IMO, just simply using Response.Write(yourJSCodehere) to client << >>

      S 1 Reply Last reply
      0
      • E enjoycrack

        Hi there, IMO, just simply using Response.Write(yourJSCodehere) to client << >>

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

        Enjoycrack, Thanks much for your response.But when I tried this I couldn't see the expected result.That is it is executing the script and the html is rendered to the page.I don't want this.When I tried with 'RegisterStartupScript' it was working and showing the executing the javascript after rendered the html.But still it is showing the posting back after executing the script.I dreally need first complete the post back and execute the script. Means after the execution of the script no remaining post back should happen.. Any way is there...:omg: Thank You, Siju Thomas.

        E 1 Reply Last reply
        0
        • S SIJUTHOMASP

          Enjoycrack, Thanks much for your response.But when I tried this I couldn't see the expected result.That is it is executing the script and the html is rendered to the page.I don't want this.When I tried with 'RegisterStartupScript' it was working and showing the executing the javascript after rendered the html.But still it is showing the posting back after executing the script.I dreally need first complete the post back and execute the script. Means after the execution of the script no remaining post back should happen.. Any way is there...:omg: Thank You, Siju Thomas.

          E Offline
          E Offline
          enjoycrack
          wrote on last edited by
          #4

          Hi, I still cannot think of which situation that you want to do that...:doh: But anyway, if you just want to execute js code and not do post back after executing js code, just simply return false in your js code as "return false" causes browser not post back to server Hope you get the idea << >>

          1 Reply Last reply
          0
          • S SIJUTHOMASP

            Hai, How I can execute a javascript after a post back event occured.Please help me by showing the right way... Thank You, Siju Thomas.

            A Offline
            A Offline
            Arvind B
            wrote on last edited by
            #5

            Hi Place below code after post back event handler If Not IsClientScriptBlockRegistered("anyNameToIdentify") Then RegisterClientScriptBlock("anyNameToIdentify", "alert('here ya go !')") .......... ..........

            1 Reply Last reply
            0
            • S SIJUTHOMASP

              Hai, How I can execute a javascript after a post back event occured.Please help me by showing the right way... Thank You, Siju Thomas.

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

              Enjoycrack , arv169, Thanks very much for your responses.I have given more explanation about my issue to get the proper solution. Please see the function given below, Private Sub MyMessage(ByVal strMsg As String) Dim strScript As String = " " ' strScript += "window.onload=alert('hai alert');" 'strScript += "alert(""" & strMsg & """);" If (strMsg <> "") Then If (strMsg = "CLOSE") Then strScript += "window.close();" Else strScript += strMsg End If End If 'strScript += "return false;" strScript += "" 'Response.Write(strScript) If (Not Page.IsStartupScriptRegistered("clientScript")) Then Page.RegisterStartupScript("clientScript", strScript) 'Page.RegisterClientScriptBlock("clientScript", strScript) End If End Sub Here 'strMsg' is the javascript which comes from user specification(Means user can execute any javascript). I have executed it under 'Page_Load' event after doing every operation. Here it is rendering the html and executing the javascript.This one I required. But the only one problem comes is after executing the javascript only it completes the post back. that is the status bar remains in half when executing javascript and ends the post back. I need it should complete the post back and execute the javascript. For example if i specify the script:- alert('hai'); it must show the message after the posting back complete. Currently it is showing the message half the way of post back and when i click ok button of the alert message box it is completing the post back.. I beleve you got the point.. Any chance....:confused:

              G 1 Reply Last reply
              0
              • S SIJUTHOMASP

                Enjoycrack , arv169, Thanks very much for your responses.I have given more explanation about my issue to get the proper solution. Please see the function given below, Private Sub MyMessage(ByVal strMsg As String) Dim strScript As String = " " ' strScript += "window.onload=alert('hai alert');" 'strScript += "alert(""" & strMsg & """);" If (strMsg <> "") Then If (strMsg = "CLOSE") Then strScript += "window.close();" Else strScript += strMsg End If End If 'strScript += "return false;" strScript += "" 'Response.Write(strScript) If (Not Page.IsStartupScriptRegistered("clientScript")) Then Page.RegisterStartupScript("clientScript", strScript) 'Page.RegisterClientScriptBlock("clientScript", strScript) End If End Sub Here 'strMsg' is the javascript which comes from user specification(Means user can execute any javascript). I have executed it under 'Page_Load' event after doing every operation. Here it is rendering the html and executing the javascript.This one I required. But the only one problem comes is after executing the javascript only it completes the post back. that is the status bar remains in half when executing javascript and ends the post back. I need it should complete the post back and execute the javascript. For example if i specify the script:- alert('hai'); it must show the message after the posting back complete. Currently it is showing the message half the way of post back and when i click ok button of the alert message box it is completing the post back.. I beleve you got the point.. Any chance....:confused:

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Put the javascript code in a function, and call that function from the onload event in the body tag. --- b { font-weight: normal; }

                S 1 Reply Last reply
                0
                • G Guffa

                  Put the javascript code in a function, and call that function from the onload event in the body tag. --- b { font-weight: normal; }

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

                  Hai Guffa, I am sorry for my late reply.Thanks much for your response.Can you elaborate by giving some examples.Thanks very much Thank You, Rahul.P.Menon

                  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