Call Javascript from Code Behind

There are time when you need to call your Javascript function from code behind.
You can achieve the same using below code,

Javascript function to call
function ConfirmBox(objMsg)
    {
        if(confirm(objMsg))
        {
            alert('test');
            return true;
        }
        else
        {
            return false;
        }
    }

C# Code Behind
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmBox('" + str + "');", true);

Or
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "alert('" + str + "');", true);
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More