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

Windows open in itemCommand event

5 Answers 106 Views
Window
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 03 May 2017, 05:16 PM

When i use this code in the page_load it opens the window as expected, when I use it in the itemCommand (and it runs in the debugger) it does not and I dont see any errors?

 

RadWindow fileWindow = new RadWindow();
        fileWindow.NavigateUrl = "http://www.google.com";
        fileWindow.VisibleOnPageLoad = true;
        fileWindow.ID = "fileWindow1";
        fileWindow.Width = 500;
        fileWindow.Height = 300;
        fileWindow.InitialBehaviors = WindowBehaviors.Maximize | WindowBehaviors.Close | WindowBehaviors.Resize;
        RadWindowManager2.Windows.Add(fileWindow);

5 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 03 May 2017, 05:37 PM
I don't work for Telerik and there might be a better solution or workaround, but if I am following you are you saying you are calling the code on an item_command from like say a RadGrid perhaps?
If so then it’s in a postback, and it’s probably losing its value -settings.
Try setting a hiddenField value in the item_command then check the hiddenField value on pageLoad() and based of the hiddenField value run your block of code.
Thanks John
0
david
Top achievements
Rank 1
answered on 03 May 2017, 06:11 PM
Hi John, thanks so much for your reply. It is onitemcommand in a grid that is the problem, the window runs fine on page_load but wont open in the event handler.  I tried the hiddenfield, problem is page_load is run first and so the hiddenfield is not set yet by the itemcommand event. Not sure whats going on perhaps the postback is destroying the window object?
0
John
Top achievements
Rank 1
answered on 03 May 2017, 06:24 PM

Try checking the hiddenField value in client side JavaScript and open it something like this.

Yes I know its ugly but it works.

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function pageLoad(sender, eventArgs) {
var $ = $telerik.$;
var hid = $get("<%= HiddenFieldConfirm.ClientID%>").value;
if (hid == 1) {

//PLACE YOUR CODE IN THIS BLOCK
$get("<%= HiddenFieldConfirm.ClientID%>").value = 0;
$find("<%= RadWindow1.ClientID%>").show();

                }
}
</script>
</telerik:RadScriptBlock>

0
david
Top achievements
Rank 1
answered on 08 May 2017, 01:15 PM

Simplified but still not sure why necessary, here is what I ended up with that works:

.cs

      RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", "showFile2('" + path + "' );", true);

.ascx

  function showFile2(path) {
            var oWindow = window.radopen(path, null, 800, 750, 50, 50);
        }

this code works fine in the page_load but does not work in item_Command:

RadWindow fileWindow = new RadWindow();
        fileWindow.NavigateUrl = "http://www.google.com";
        fileWindow.VisibleOnPageLoad = true;
        fileWindow.ID = "fileWindow1";
        fileWindow.Width = 500;
        fileWindow.Height = 300;
        fileWindow.InitialBehaviors = WindowBehaviors.Maximize | WindowBehaviors.Close | WindowBehaviors.Resize;
        RadWindowManager2.Windows.Add(fileWindow);

0
John
Top achievements
Rank 1
answered on 08 May 2017, 06:48 PM

Yes I do something similar for my toastr.js notifications, and other things when I need to kick something off after a postback.

Also don't forget to url encode the path especially if you have &parms.

If you start to have any weird issues try using the ScriptManager.RegisterStartupScript instead of the RadScriptManager even if you are using the Telerik Script Manager

Glad you got it working

 

Tags
Window
Asked by
david
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
david
Top achievements
Rank 1
Share this question
or