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

Radwindow reopening after closing it in every postback

23 Answers 1050 Views
Window
This is a migrated thread and some comments may be shown as answers.
NLV
Top achievements
Rank 1
NLV asked on 16 Mar 2010, 05:11 PM
Hello team

I've the following issue with the radWindow -

I've two buttons "Open Popup" and "Do Postback". Open Popup opens a page in radwindow and Do Postback just does an empty postback.

I'm opening a page in the radwindow when Open Popup is clicked. I've a cancel button in the popup page which simply closes the radwindow (using client side script).

Now when i do an empty postback the popup is getting opened again. Why is that happening?

I've uploaded the project here to duplicate the issue - http://dl.dropbox.com/u/3971218/Code%20Samples/RadWindowAsPopup.zip.

Kindly check it out.

Regards
NLV

23 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Mar 2010, 09:15 AM

Hi,

Since you are setting the VisibleOnPageLoad property to True, the window will be open for every postback. So one suggestion would be opening the window from client code as shown below.

C# code for invoking the client event handler which opens the window:

 
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(showWindow);</script>";  
ClientScript.RegisterStartupScript(this.GetType(), "showWindoww", script);    
 

JavaScript:

 
    <script type="text/javascript">  
        function showWindow() {  
 
            radopen('url''');  // Opens the window
        }  
    </script> 

-Shinu.

0
NLV
Top achievements
Rank 1
answered on 17 Mar 2010, 10:21 AM
Hello Shinu,

I want to pass the URL to the showWindow function which i've built in the code. How can i do that?

Thank you.

Regards
NLV
0
robertw102
Top achievements
Rank 1
answered on 18 Mar 2010, 03:09 PM
Just change the line where you create the script to this:

string script = String.Format("<script language='javascript' type='text/javascript'>Sys.Application.add_load(showWindow('{0}');</script>",url); 

Where url is the url that you generated. You then change the showWindow javascript function to this:

<script type="text/javascript">   
        function showWindow(url) {   
  
            radopen(url, '');  // Opens the window 
        }   
    </script> 

I just added the url parameter to the showWindow function.

I hope that helps.
0
NLV
Top achievements
Rank 1
answered on 18 Mar 2010, 06:40 PM
Obviously i tried it and it is not working!

I'll give it a try again.

Regards
NLV
0
Svetlina Anati
Telerik team
answered on 19 Mar 2010, 02:13 PM
Hi NLV,

There are several ways to resolve the problem. What I suggest is that you put the url from the server in a HiddenField and then on the client reference the filed and get the url value.


Best wishes,
Svetlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
NLV
Top achievements
Rank 1
answered on 19 Mar 2010, 07:22 PM
Thats a good idea. I'll do it.

Thank you Svetlina.

Regards
NLV
0
Muhammad
Top achievements
Rank 1
answered on 15 Feb 2011, 05:50 PM
I have the same problem and my radwindow is within the same page and contains some controls I want to show my radwindow when the user clicks a button. I don't need to pass the url but when I click on a button when window doesn't open.

 Protected Sub ShowCustomerWindow()   


        Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "showWindow();", True)


    End Sub

 function showWindow() {


                var oWindowCust = $find('<%= rwJobEventLog.ClientID %>');               
                oWindowCust.show();
                
            }  


   <telerik:RadWindow ID="rwJobEventLog" runat="server" Title="Job Event Log" Width="350" 
            Height="520" VisibleOnPageLoad="true" Behaviors="Move,Pin,Resize" InitialBehaviors="Pin"
            KeepInScreenBounds="true" OffsetElementID="lnkbtnViewJobEventLog" Left="580"
            Visible="false" CssClass="rwBasket" DestroyOnClose="true">
            <ContentTemplate>
                <div style="text-align: center">
                    <table>
                        <tr>
                            <td style="width: 75%">
                                <asp:Button ID="btnJobEventLogCloseWindow" runat="server" Text="Close Window" OnClientClick="return CloseEventLogWindow();" 
                                 />
                            </td>
                            <%--                                <td style="width: 25%" align="right">
                                    <asp:Image ID="Image1" runat="server" ImageUrl="~/DesktopModules/phdcc.CodeModule/images/help.gif" />
                                </td>
                            --%>
                        </tr>
                    </table>
                    <asp:GridView ID="gvJobEventLog" runat="server" CellPadding="2" Width="95%" CssClass="gridviewSpacing gvBasket"
                        AutoGenerateColumns="True">
                        <Columns>
                        </Columns>
                    </asp:GridView>
                </div>
                <br />
            </ContentTemplate>
        </telerik:RadWindow>
0
Svetlina Anati
Telerik team
answered on 17 Feb 2011, 02:44 PM
Hello rMuhammad,

 I already answered your other thread and for your convenience and for others who need more detailed information about the AJAX client lifecycle, I pasted it below:
 
The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls (including RadWindow) in the Sys.Application.add_init() method.

Here is how the client events are fired in the page life cycle:

window.onload -> Sys.Application.init -> Sys.Application.load

You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.

That is why when you call your code in window.onload by registering the client script, the RadWindow will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.

You can find additional information about this here:

http://blogs.telerik.com/blogs/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx

This being said, you should modify your code e.g in the following manner:

Copy Code
Protected Sub lbAddCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbAddCustomer.Click
      Page.ClientScript.RegisterStartupScript(Me.GetType(), "key", "Sys.Application.add_load(showWindow);", True
        
      End Sub

 

Copy Code
<script type="text/javascript">
    function showWindow() {
        Sys.Application.remove_load(showWindow);
        var oWindowCust = $find('<%= rwCustomer.ClientID %>');
        oWindowCust.show();
    }  
</script>

I hope that the provided explanation and resource are helpful .

Regards,
Svetlina
the Telerik team

0
Muhammad
Top achievements
Rank 1
answered on 18 Feb 2011, 01:30 AM
Thanks for your reply but when I am trying to find my
radwindow ( var oWindowCust = $find('<%= rwCustomer.ClientID %>');
I am getting undefined.

And when I set VisibleOnPageLoad=true and visible=true then my radwindow appears at page load
and I can close my radwindow at client side using javascript. I don't understand really what's
happening.

               function GetEventLogWindow() {


            var oWindowViewJobLog = $find('<%= rwJobEventLog.ClientID %>');
            return oWindowViewJobLog;
        }

 function GetCustomerWindow() {
            var oWindowCust = $find('<%= rwCustomer.ClientID %>');       
             
               return  oWindowCust;
            }

        function CloseCustomerWindow() {


            GetCustomerWindow().close();
        }


        function CloseEventLogWindow() {


            GetEventLogWindow().close()
            


        }







0
Svetlina Anati
Telerik team
answered on 23 Feb 2011, 10:55 AM
Hello Muhammad,

I am afraid that I could not understand what is the problem - would you please prepare a simple, fully runnable reproduction page and post the full and working source code here? In case you have followed my suggestion, you can directly pass the ClientID from the server, no need to use code blocks to evaluate it. If you have decided, on the other hand, to use the VisibleOnPageLoad property, I did not understand what is the issue you face. At last, the Visible property should not be used - it is only inherited and not implemented.

This being said, to be able to help I will really need to have an overall understanding on the configuration - please provide sample working full source code along with detailed explanations on each reproduction step and I will modify it in order to meet your requirements. 

Greetings,
Svetlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Muhammad
Top achievements
Rank 1
answered on 23 Feb 2011, 02:36 PM
Hi,

My Scenario

It's a very simple scenario ... Just place three radwindows in a webform with three buttons and make sure that radwindow should be hidden at page load (visible = false , VisibleOnPageLoad =true) and will only be visible when user clicks a button. Radwindow should be opened from code-behind and close it at client-side using javascript.

Steps:

1) Three Radwindows
2) Three Buttons
3) Open from Code-Behind
4) Close By using javascript

When you implement this what will happen that when you open a first window you will either get undefined or if it opened successfully then close it and when you try to open a second window a first window will also appears again. I hope you understand and if you still need a code for that simple scenario then reply me back.






0
Svetlina Anati
Telerik team
answered on 23 Feb 2011, 02:46 PM
Hi Muhammad,

In this case, the easiest way to achieve what you want is the following:

1) Wrap the RadWindows in a RadWindowManager with EnableViewState="false".
2) Use the VisibleOnPageLoad property to show the RadWindow you want.

Wrapping the RadWindows with a manager with disabled ViewState will remove the problem with reopening the first RadWindow when opening the second. Note, that this will work in the case of RadWindows wrapped in a RadWindowManager.

Kind regards,
Svetlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Muhammad
Top achievements
Rank 1
answered on 23 Feb 2011, 04:11 PM
Its not a good solution because In my radwindow I have a form in which when I press any button and the postback occurs and radwindow hides :(
0
Michael Fernandez
Top achievements
Rank 1
answered on 23 Feb 2011, 09:50 PM
Hello Muhammad,

I was having the same issue like yours before. To solve this issue I created a new separate aspx page with all the controls that I need to show on the page then generate the RADWindow on the fly via button click event. Make sure to assign the NavigateURL property of the RADWindow to the new aspx page that you created. See example below. Hope this helps.

protected void lnkBtn_Click(object sender, CommandEventArgs e)
        {
            string navigateURL = string.Format("OrderDetail.aspx{0}", StringHelpers.EncryptQueryString(e.CommandArgument.ToString()));
            //Create RadWindow dynamically
            RadWindow orderDetailWindow = new RadWindow();
            orderDetailWindow.ID = "OrderDetailWindow";
            orderDetailWindow.Title = "Order Detail";
            //orderDetailWindow.Skin = "Web20";
            orderDetailWindow.Width = Unit.Pixel(960);
            orderDetailWindow.Height = Unit.Pixel(600);
            orderDetailWindow.VisibleStatusbar = false;
            orderDetailWindow.ShowContentDuringLoad = false;
            orderDetailWindow.Modal = true;
            orderDetailWindow.AutoSize = false;
            orderDetailWindow.Behaviors = WindowBehaviors.Close | WindowBehaviors.Move;
            orderDetailWindow.NavigateUrl = navigateURL;
            orderDetailWindow.VisibleOnPageLoad = true;
  
            gridOrders.Controls.Add(orderDetailWindow);
  
        }
0
Svetlina Anati
Telerik team
answered on 25 Feb 2011, 03:55 PM
Hello Muhammad,

I am afraid that there is some misunderstanding between us - do you want to have the RadWindows opened or not on postbacks? It seems that we can't get a good enough understanding on your overall scenario, please prepare a simple reproduction demo which is fully runnable and send its full source code. Put along very detailed step by step instructions and detailed explanations on the exact actual and desired result on each of the steps. Once we receive this, we will be able to provide you a faster and better support rather then exchanging pieces of information which seem to be insufficient.

 Best wishes,
Svetlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Francesco
Top achievements
Rank 1
answered on 22 Mar 2011, 04:59 PM
I had the same problem but I have resolve quickly. The problem is done because the server side and client site not "speak" well.
When Open from Code-Behind we set  RadWindows1.VisibleOnPageLoad ="True" it popup and the ViewState save this property to TRUE!!!! Then when we close by client script the RadWindows hide correcly.
But on postBack the server recall ViewState and the property RadWindows1.VisibleOnPageLoad will set to TRUE and will popUp.

I suggest to set in Page_load server side event RadWindows1.VisibleOnPageLoad = "False"; as default!


If you set EnableViewState="false" you lost all property set in server side, is dangereus.

thanks
0
Muhammad
Top achievements
Rank 1
answered on 22 Mar 2011, 05:38 PM
That's the thing I was asking with telerik guys ... Thank you so much ... 
0
Svetlina Anati
Telerik team
answered on 23 Mar 2011, 10:27 AM
Hello guys,

The behavior you report is actually the expected one - when a property is set it should be persisted in the ViewState. The property says that the RadWindow should be visible on page load - it is absolutely valid scenario to have it always initially opened on the page. However, as already explained you can use the same property and reset it to false where needed - this is up to your custom logic. Another option is to execute opening script from the server - it is up to you to choose the approach which meets your preferences.

What exactly do you mean by saying that "If you set EnableViewState="false" you lost all property set in server side, is dangereus"? Disabling the ViewState is a valid approach which is actually often used in general ASP.NET to make the pages lighter and faster. You will lose properties you set only if you set them once - e.g on initial load. You could set them always or use the page's ViewState or Session object to keep the setting.

Please, choose one of the already suggested 3 approaches and let us know if you need further assistance with the approach you have chosen. 

Kind regards,
Svetlina
the Telerik team
0
Andy
Top achievements
Rank 1
answered on 30 Mar 2011, 01:39 PM

Good day!
Here's my scenario:
- on web page there's a button "A" to pop up rad window
- rad window has some controls (rad grid) which may cause post backs, so after those post-backs rad-window needs to be opened
- rad window also has a link-button B to save and close the form

So, when user needs to open the dialog, he clicks button A, and in click-event handler I  set VisibleOnPageLoad to "true".
When user clicks button B to close the form, in the event handler I set VisibleOnPageLoad = "false".

Everything works fine for the exception, that user can also close the window with the "X" button in the top-right corner. In this case the window will re-appear after the next post-back. The solution I use is to make the window to do the post-back when X button is clicked. It can be done by rendering post-back script from "B" button to the javascript function and assigning this function to OnClientClose property of the RadWindow.

Here's the code to render the method:

protected override void Render(HtmlTextWriter writer)
        {
            ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "scrCancelWindow",
                string.Format(@"function onWindowClose(sender, eventArgs){{{0};}}",

Page.ClientScript.GetPostBackEventReference(lbCancel, lbCancel.ID,

true);

 

),
true);
            base.Render(writer);
        }

Make sure you render post-back script in overriden Render method of the page, otherwise you'll get an exception. Hope this will help someone.

0
Silvio Silva Junior
Top achievements
Rank 2
answered on 09 May 2011, 02:41 PM
I suggest to set in Page_load server side event RadWindows1.VisibleOnPageLoad = "False"; as default!

Amazing!

Regards.
0
Nitesh
Top achievements
Rank 1
answered on 22 May 2012, 10:14 AM
Thats the best solution for this problem according to me, i am also using the RadWindow for a pop up from within a grid to use it for document upload and i think the best thing is to set the visible property to false, 

Thankyou Fransesco.
0
Santosh
Top achievements
Rank 1
answered on 13 Nov 2013, 05:27 AM
Hello,
My Issue is in radwindow when i click on "close" button page is loading after page is loaded radwindow will be closed but we want to close the window without page load....is their any way to solve this issue??? 
0
Marin Bratanov
Telerik team
answered on 14 Nov 2013, 02:27 PM
Hi Santosh,

When RadWIndow's [X] close button (at the top right corner, in LTR mode) is clicked it only executes a JavaScript function that hides the popup. In case either the content, or the main page reloads, then some custom code is most likely involved, so you should look for OnClientClose or OnClientBeforeClose handlers that can be doing this.

In case you have a custom button on the content page of the RadWindow and you want to close it via this button's client-side code, please examine the following demo's content page which shows such an example: http://demos.telerik.com/aspnet-ajax/window/examples/contenttemplatevsnavigateurl/defaultcs.aspx.


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Window
Asked by
NLV
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
NLV
Top achievements
Rank 1
robertw102
Top achievements
Rank 1
Svetlina Anati
Telerik team
Muhammad
Top achievements
Rank 1
Michael Fernandez
Top achievements
Rank 1
Francesco
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Silvio Silva Junior
Top achievements
Rank 2
Nitesh
Top achievements
Rank 1
Santosh
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or