call the jQuery function from the code behind to main page load page

advertisements

I am calling a jQuery function from code behind in my master page on page load, and it is returning this error:

ReferenceError: $ is not defined

Code Behind:-

protected void Page_Load(object sender, EventArgs e)
{
    string script = "$(document).ready(function () {alert('hello'); });";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
}

I also tried this jquery function :-

ScriptManager.RegisterStartupScript(Page, typeof(Page), "ShowProgressBar", "ShowProgressBar();", true);

but then getting the error "ShowProgressBar is not defined".


Try this,

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Function1", "yourFunction();", true);