One can call JavaScript client side function directly from code behind using RegisterStartupScript. If one wants JavaScript to be embedded into codebehind, then make use of RegisterClientScriptBlock:
<script>
function fnShowMessage()
{
alert(" Invoke Javascript function from Server Side Code Behind ");
}
</script>
function fnShowMessage()
{
alert(" Invoke Javascript function from Server Side Code Behind ");
}
</script>
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript (GetType(),"Javascript", "javascript: fnShowMessage(); ",true);
}
protected void Button2_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Record Added Successfully')</script>");
}
{
ClientScript.RegisterStartupScript (GetType(),"Javascript", "javascript: fnShowMessage(); ",true);
}
protected void Button2_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Record Added Successfully')</script>");
}
0 comments:
Post a Comment