Custom Dialog, Javascript gets fired on PageLoad

3 posts, 1 answers
  1. Hermann
    Hermann avatar
    2 posts
    Member since:
    Nov 2013

    Posted 17 Nov 2014 Link to this post


    I used this sample to get a Custom Dialog for the Editor. On that Dialog page I added a RadButton. This RadButton has a OnClientClicked Event with a Javascript function (Dialog return). The Problem is that this function gets fired on PageLoad (Dialog\RadWindow). If i use a normal ASP Button with "OnClientClick" all works fine. How is it possible to have the JavaScript function fired only on the Click event with a RadButton.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dialog.aspx.cs" Inherits="TelerikSample.Dialog" %>

    <!DOCTYPE html>

    <html xmlns="">
    <head runat="server">
    <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:RadButton ID="RadButton1" runat="server" Text="RadButton" OnClientClicked="insertLink('IdOfList')"></telerik:RadButton>
    <%--<asp:Button ID="Button2" runat="server" Text="ASPButton" OnClientClick="insertLink('IdOfList')" ></asp:Button>--%>

    <script type="text/javascript">

    function getRadWindow() {
    if (window.radWindow) {
    return window.radWindow;
    if (window.frameElement && window.frameElement.radWindow) {
    return window.frameElement.radWindow;
    return null;

    function insertLink(Id) //fires when the Insert Link button is clicked
    getRadWindow().close(Id); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.

  2. Answer
    Marin Bratanov
    Marin Bratanov avatar
    3555 posts

    Posted 18 Nov 2014 Link to this post

    Hello Hermann,

    In order to use the client-side events of our controls, you should pass only the function name without parentheses, otherwise you will get the function executed as soon as the page loads because the parentheses in the $create() statement of the control will execute the function.

    I advise that you go through this blog post to see how to move from asp:Button to Telerik RadButton:


    Marin Bratanov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
  4. Hermann
    Hermann avatar
    2 posts
    Member since:
    Nov 2013

    Posted 20 Nov 2014 in reply to Marin Bratanov Link to this post

    Hey Marin,

    thank's, it is working now :-)

Back to Top