How to use Javascript using Server-side scripting

Hi.
This article is interesting for those who loves to use javascript, but with little server postbacks. I had some times issues related to validation or client redirection or other sorts. So i got this solution and i would like to share it with you.
Here I am presenting a scenario. I have a button, and OnClick of this button, i want to call java script function.

On Server Side (.aspx.cs)
--------------------------
Write this code under Button_Click event or in any server event.

ClientScript.RegisterStartupScript(this.GetType(), "key", "SubmitConfirm();",true);

You can also pass server control, properties to the "SubmitConfirm();" function.

On Client Side (.aspx)
--------------------------
write within javascript tag

function SubmitConfirm()

{

  alert('Form Submitted and Information Sent to naveedmcp@yahoo.com');

  window.location='TestPage.aspx';

}
-------------------------------------

kick it on DotNetKicks.com

Published Saturday, June 28, 2008 9:24 PM by NavaidAkhtar

Comments

# How to use Javascript using Server-side scripting

Monday, July 07, 2008 5:27 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Leave a Comment

(required) 
(required) 
(optional)
(required)