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

[Solved] Postback And Close On Reload

5 Answers 618 Views
Window
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 26 Nov 2007, 02:58 PM
Hi,

I am trying to get the sample "Postback And Close On Reload" running for my own dialog box but always getting java-script error for some objects not found.

What I basically try to do is combine the online sample "Using RadWindow URL to supply server arguments" and the help sample "Postback And Close On Reload". The first one works quite well but the second does not.

Here is what I did so far:

In the parent page I am open the dialog with a js-function like this:
<script type="text/javascript">
    function openRadWindow(VoterID, EventID)
    {
       var oWnd = radopen("DialogVoterDelete.aspx?voterid=" + VoterID + "&eventid=" + EventID, "TrashConfirmWindow" );
       oWnd.Center();
    }
</script>
The dialog contains two buttons - "Yes" and "No". Both of them are doing a server postback. "No" should just close the dialog while "Yes" sould to some server-side action, close the dialog and refresh the parent page.

Therefore I've added the following JScript on the dialog.aspx:
<script type="text/javascript">
    //This code is used to provide a reference to the radwindow "wrapper"
    function GetRadWindow()
    {
       var oWindow = null;
       if (window.RadWindow1) oWindow = window.RadWindow1; //Will work in Moz in all cases, including clasic dialog
       else if (window.frameElement.RadWindow1) oWindow = window.frameElement.RadWindow1;//IE (and Moz az well)
       return oWindow;
    }

    function CloseOnReload()
    {
       GetRadWindow().close();
    }

    function RefreshParentPage()
    {
       GetRadWindow().BrowserWindow.location.reload();
    }
</script>
In the dialog.aspx I inserted a literal named "InjectScript" with the "passthrough" option set. On the server-side (C#) I've implemented the two methods below:
private void CloseDialogOnRefresh()
{
    InjectScript.Text = "<script>CloseOnReload()</script>";
}

private void RefreshParentPage()
{
    InjectScript.Text = "<script>RefreshParentPage()</script>";
}
These two functions where called from the server-side Click-Handlers but none of them works. Both results in a JScript error for some Null-References within the dialog.aspx.

I am not really sure what are control names and what are types in the JScript code above. For example as I understood the RadWindow created is named  "TrashConfirmWindow". Do I need to refer to the from the dialog by its name? Tried this as well (instead of ".RadWindow") but did not work neighter.

Does anybody have an idea what is going wrong here?

Thanks and cheers,
Marc

5 Answers, 1 is accepted

Sort by
0
Jason Maronge
Top achievements
Rank 1
answered on 26 Nov 2007, 04:47 PM
Marc,

   Is the JS error happening in the GetRadWindow?  If so try this code:

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

This is the code I am using everywhere I need to do something like this.  Also try doing a show() when opening the window.  I seem to remeber having a JS error occur when I called close but not show.  Call show() before you call center()

Hope this helps..

Jason 
0
Roger
Top achievements
Rank 1
answered on 27 Nov 2007, 08:33 AM
Thanks a lot! I think the show() solved my jscript errors!

btw: do you know how i can darken/lighten the background (parent page) in the above szenario while the dialog is shown and how to remove the titlebar-icons like maximize, minimize etc.? i guess i have to do it somehow in the jscript code before the show(). correct?

cheers, marc
0
Georgi Tunev
Telerik team
answered on 27 Nov 2007, 09:43 AM
Hi Marc,

If you are referring to the modal background that appear for example in this demo, it will be used when you set the RadWindow's Modal property to true.

As for the buttons in the titlebar, you can control them with the Behaviors property. Set the enum only for the actions you would like to allow and the rest of the icons will not be displayed.
e.g. if you want to clear all icons, you can set Behaviors="Move, Resize".

More information on the Behaviors property is available in the control's documentation.



Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger
Top achievements
Rank 1
answered on 27 Nov 2007, 10:18 AM
thanks this solved it.

what i did is adding a window to the RadWindowManager's window collection with the same name and configure its props in the VS-designer. this seems to work well.

cheers, marc
0
rh
Top achievements
Rank 1
answered on 16 Feb 2008, 02:41 PM
Using the label as an inject script doesn't work for me in prometheus. I was able to make the following work within prometheus, though:

Place a panel with a RadScriptBlock that can be updated by the postback:

<asp:Panel ID="pnlScriptBlock" runat="server">  
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
<script type="text/javascript">  
<%= this.ScriptToLoad %> 
</script> 
</telerik:RadScriptBlock> 
</asp:Panel> 

Configure your RadAjaxManager or manager proxy to update the panel on the postback:



<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnSave" EventName="Click">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="pnlScriptBlock" LoadingPanelID="AjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 

Put a property in your code behind to set the text for the script:

private string _scriptToLoad = String.Empty;  
protected string ScriptToLoad  
{  
    get { return _scriptToLoad; }  
} 

Then set the script in your postback:

protected void btnSave_Click(object sender, EventArgs e)  
    {  
        DoSomeServerSideWork();
        _scriptToLoad = "CloseWindow();";  
    } 


Tags
Window
Asked by
Roger
Top achievements
Rank 1
Answers by
Jason Maronge
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Georgi Tunev
Telerik team
rh
Top achievements
Rank 1
Share this question
or