Windows open in itemCommand event

6 posts, 0 answers
  1. david
    david avatar
    228 posts
    Member since:
    May 2007

    Posted 03 May 2017 Link to this post

    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);

  2. John
    John avatar
    10 posts
    Member since:
    Aug 2013

    Posted 03 May 2017 in reply to david Link to this post

    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
  3. david
    david avatar
    228 posts
    Member since:
    May 2007

    Posted 03 May 2017 in reply to John Link to this post

    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?
  4. John
    John avatar
    10 posts
    Member since:
    Aug 2013

    Posted 03 May 2017 Link to this post

    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>

  5. david
    david avatar
    228 posts
    Member since:
    May 2007

    Posted 08 May 2017 in reply to John Link to this post

    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);

  6. John
    John avatar
    10 posts
    Member since:
    Aug 2013

    Posted 08 May 2017 in reply to david Link to this post

    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

     

Back to Top