Domanda

I'm trying to use a RadButton to close a radwindow from with the window itself (via javascript). Is it possible to call a script to close the window? Here is the javascript:

function getRadWindow() 
{
  var oWindow = null;
  if (window.radWindow) oWindow = window.radWindow;
  else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
  return oWindow;
}

function closeWindow() 
{
  getRadWindow().close();
}

And here is the button:

<telerik:RadButton ID="CancelButton" runat="server" OnClick="closeWindow();" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">
</telerik:RadButton>

I have tried everything, the script will only work if I use a pure HTML element such as an anchor tag. If I use the OnClick event I get the following error when the window opens: Compiler Error Message: CS1026: ) expected.

Am I missing something?

Thanks!

È stato utile?

Soluzione

The way to call a function from the RadButton is by using either its OnClientClicked or OnClientClicking event. Then you need to pass only the name of the JavaScript function, without parenthese. OnClick is a property for the server handler, this is also the case with the regular asp button. Try this:

<telerik:RadButton ID="CancelButton" runat="server" OnClientClicked="closeWindow" AutoPostBack="false" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">

Note the AutoPostBack property is set to false to prevent the postback.

Altri suggerimenti

I'm not sure if I am improving this answer, I'm just trying to make it easier to understand. I have a rad window that is opened from a main page. The radwindow is opened in Code Behind (C#), not Javascript. When my user clicks a Save button on the RadWindow, it performs some logic tasks, then it closes the radwindow itself. You simply need to:

Put thise code block in you RadWindow aspx.....

<telerik:RadCodeBlock runat="server" ID="rcb1">
<script language="javascript" type="text/javascript">

function GetRadWindow() 
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseDialog(button) 
{
GetRadWindow().close();
}  

</script>
</telerik:RadCodeBlock>

Put this code in your RadWindow's button click after you perform your pre-close logic (the same button that performs the other logic closes the window)

C# ClientScript.RegisterStartupScript(typeof(string), "", "CloseDialog();");

OR

VB ClientScript.RegisterStartupScript(Me.GetType(), "", "CloseDialog();")

If you're wondering how to open the radwindow from codebehind here is how I did it:

RadWindow window1 = new RadWindow();
// Set the window properties   
window1.NavigateUrl = "winStrengthChart.aspx?EMPLOYIDNAME=" + parmString;
window1.ID = "RadWindow1";
window1.Width = 800;
window1.Height = 650;
window1.VisibleStatusbar = false;
window1.Behaviors = Telerik.Web.UI.WindowBehaviors.Close | Telerik.Web.UI.WindowBehaviors.Resize | Telerik.Web.UI.WindowBehaviors.Move;
window1.VisibleOnPageLoad = true; // Set this property to True for showing window from code   
rwm1.Windows.Add(window1);
this.Form1.Controls.Add(window1);   

...AND of course you need a basic RadWindowManager on the main page that opens the window:

<telerik:RadWindowManager ID="rwm1" runat="server">
<Windows>
</Windows>
</telerik:RadWindowManager>

This should work if I have made a mistake please correct me.

Thanks

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top