How to execute a javascript after a post back event occured??
-
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.
-
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.
Hi there, IMO, just simply using
Response.Write(yourJSCodehere)
to client << >> -
Hi there, IMO, just simply using
Response.Write(yourJSCodehere)
to client << >>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.
-
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.
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 << >> -
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.
-
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.
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: -
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: -
Put the javascript code in a function, and call that function from the onload event in the body tag. --- b { font-weight: normal; }
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