Search This Blog

Loading...

Nov 19, 2010

How to call a Java Script Method – 2


Sponsored Links:

Writing JavaScript in HTML and Calling it from Code behind.

<script type ="text/javascript" language="javascript">
function
myFunction(str)
{
alert(str);
}
</script>

1) Without Using RegisterStartupScript In Code behind

protected void Page_Load(object sender, EventArgs e)
{
Button2.Attributes.Add
("onclick", "javascript:myFunction('from code behind');");
}
image 

2) Using RegisterStartupScript in Code Behind

protected void Button3_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript
(typeof(testJavaScript), "alert",
"<script language='javascript'>myFunction('" + TextBox1.Text + "');</script>");
}

image



*Using RegisterStartupScript we can call javascript from code behind.

Follow by Email