This is a migrated thread and some comments may be shown as answers.

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

1 Answer 848 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
hamid
Top achievements
Rank 1
hamid asked on 19 Feb 2016, 06:49 PM

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <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;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <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" />
            </Scripts>
        </telerik:RadScriptManager>
 
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            (function ($) {
                $(document).ready(function () {
                    function showmsg() {
                        $("#msg").show(2000).delay(3000).hide(2000);
                    }
                });
            })($telerik.$);
        </script>
    </telerik:RadScriptBlock>
 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadButton1">
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadButton1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadButton1" UpdatePanelCssClass=""></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <div>
 
            <telerik:RadButton ID="RadButton1" runat="server" Text="RadButton" OnClick="RadButton1_Click">
            </telerik:RadButton>
        </div>
        <div id="msg">
            Hi Telerik team...
        </div>
    </form>
     
</body>
</html>

protected void RadButton1_Click(object sender, EventArgs e)
   {
       System.Threading.Thread.Sleep(1000);
       ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showmsg();", true);
 
   }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Feb 2016, 08:06 AM
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.

Regards,
Eyup
Telerik
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
Tags
Ajax
Asked by
hamid
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or