Call javascript function (contain jquery function) from code behind ?

2 posts, 0 answers
  1. hamid
    hamid avatar
    4 posts
    Member since:
    Dec 2015

    Posted 19 Feb 2016 Link to this post

    Hi Telerik team

    I have blow code and i delcare a javascript function in web page that contain a few jquery function . i wana to call it from code behind but when use it i get error .

    please help me .

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
        <style type="text/css">
            #msg {
                width: 400px;
                height: 200px;
                background-color: fuchsia;
                color: blueviolet;
                font-size: 16px;
                display: none;
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                (function ($) {
                    $(document).ready(function () {
                        function showmsg() {
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <telerik:AjaxSetting AjaxControlID="RadButton1">
                    <telerik:AjaxSetting AjaxControlID="RadButton1">
                            <telerik:AjaxUpdatedControl ControlID="RadButton1" UpdatePanelCssClass=""></telerik:AjaxUpdatedControl>
                <telerik:RadButton ID="RadButton1" runat="server" Text="RadButton" OnClick="RadButton1_Click">
            <div id="msg">
                Hi Telerik team...

    protected void RadButton1_Click(object sender, EventArgs e)
           ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showmsg();", true);
  2. Eyup
    Eyup avatar
    3323 posts

    Posted 24 Feb 2016 Link to this post

    Hello Hamid,

    Please place the function showmsg() {...} outside of its current scope. Also, please temporarily disable any AJAX on the page (RadAjaxManager, RadAjaxPanel, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script or server errors interfering.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top