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

Custom Dialog, Javascript gets fired on PageLoad

2 Answers 108 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Hermann
Top achievements
Rank 1
Hermann asked on 17 Nov 2014, 04:12 PM
Hi,

I used this sample http://demos.telerik.com/aspnet-ajax/editor/examples/customdialogs/defaultcs.aspx 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="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</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>
<div>
<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>--%>
</div>
</form>
</body>
</html>


<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.
}
</script>


Thanks,
Hermann

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 18 Nov 2014, 01:38 PM

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: http://blogs.telerik.com/aspnet-ajax/posts/12-08-10/migrating-onclientclick-handlers-from-asp-button-to-telerik-s-asp-net-ajax-button.aspx.


Regards,

Marin Bratanov
Telerik
 

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.

 
0
Hermann
Top achievements
Rank 1
answered on 20 Nov 2014, 08:17 AM
Hey Marin,

thank's, it is working now :-)

regards,
Hermann
Tags
Editor
Asked by
Hermann
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Hermann
Top achievements
Rank 1
Share this question
or