Hi,
I need to call a Jquery function from CodeBehind, I know that I should use Page.ClientScript.RegisterStartupScript() function but I don’t know how .
If you have an example of how to use it will be helpful.
Best Regards,
Sara.
Hi,
I need to call a Jquery function from CodeBehind, I know that I should use Page.ClientScript.RegisterStartupScript() function but I don’t know how .
If you have an example of how to use it will be helpful.
Best Regards,
Sara.
Hi,
jQuery functions are usually run at client-side. You can simply embed your code in the Web References
tab in the Form Designer.
Here are some articles on how you can include and execute client-side JavaScript/jQuery scripts.
Hi,
Thank you for the reply. I have already used Jquery to do some stuff in client side but I need to call a specific Jquery function from Code Behind .
Best Regards,
Hi,
The ClientScriptManager.RegisterStartupScript
method allows you to inject at client JS when the page postback. Is that what you would like to achieve?
Here is a sample process of how it is being used in the form designer. You can open the Form / .NET tabs to view the code behind I have added.
https://advantys.box.com/s/m5t46uv0sfh27bjobxduwshms6f7ipdh
// Place here your ASP.NET procedures and global variables.
// It will be declared within a <script runat="server"> block,
// and placed before the opening <html>.
// Do not include the <script runat="server"> tag.
// Use the Control key + Spacebar to show the keywords list.
// ***********************************************************
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript1";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('JS injected at Page_Load') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}
protected void REQUEST_BUTTON1_Click(object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript2";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('JS injected on custom button click event') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}
Here is another sample process that would call an existing JS function that was defined in the Web References
tab in the Form designer on click of a button.
Hi,
Thank you for your helpful reply .
Best Regards.