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 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" "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);
     
       }
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 24 Feb 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.

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top