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

[Solved] How to do server-side update from page in radwindow and then close this page

13 Answers 454 Views
Window
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 11 Mar 2008, 12:49 PM
Hi all,

I have a pop-up page called from my parent page using the radwindow control.  On my pop-up window, I have a Close button which closes the pop-up page and refreshes the parent page.  This all works great.

On my pop-up page, I also have a Save button.  The user clicks this after making changes.  This button causes a postback and saves this data.  I'd like to be able to close the pop-up window AFTER the postback occurs.  You guys helped me out with this on the Close button.  But I do not know how to make this happen after I save the data.  Can anyone help?  Here is my pop-up page code:

HTML:

<

asp:Button ID="btnUpdate" runat="server" Text="Save" />

<asp:Button ID="btnCancel" runat="server" CausesValidation="false" Text="Cancel" OnClientClick="closeWin(); return false;"/>


<
script 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 closeWin()

{

var oWnd = GetRadWindow();

oWnd.close();

top.location.href=top.location.href; originalAttribute="href" originalPath="top.location.href;" originalAttribute="href" originalPath="top.location.href;"

}

</script>



Thanks,
Bob

13 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 11 Mar 2008, 02:02 PM
Hi Bob,

In this forum post:
http://www.telerik.com/community/forums/thread/b311D-bckggg.aspx#491031

I sent you an example where this scenario was covered. Can you please let me know if you experience any problems with the suggested approach?

For convenience I am pasting the code excerpt below:
aspx:
<script 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 closeWin() 
   { 
    var oWnd = GetRadWindow();  
    oWnd.close(); 
   } 
    
</script> 
<asp:Button ID="Button3" runat="server" Text="Close RadWindow from the client" OnClientClick="closeWin(); return false;" /> 
<br /> 
<asp:Button ID="Button4" runat="server" Text="Close RadWindow by calling a client-side function from the server" />         
 
 

codebehind:
Protected Sub Button4_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button4.Click 
    Dim closingScript As String 
    closingScript = "<script type='text/javascript'>window.onload = closeWin</script> " 
    ClientScript.RegisterStartupScript(Me.GetType(), "closeWin", closingScript) 
End Sub 



All the best,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 11 Mar 2008, 09:11 PM
Georgi,

Here is the code for my link button click event:

Protected

Sub lbSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbSave.Click

If Page.IsValid Then

WorkflowTask.CreateWorkflowTask(

CInt(Session("TaskID")), _

tbTaskName.Text, _

CInt(ddlTaskType.SelectedValue))

Dim closingScript As String

closingScript =

"<script type='text/javascript'>window.onload = closeWin</script> "

ClientScript.RegisterClientScriptBlock(

Me.GetType(), "closeWin", closingScript)

End If

End Sub

I put the code you sent me right after my method that performs my update.  But my pop-up page still does not close.   I think I have all the javascript syntax correct.  Can you see anything wrong?

Bob

0
Georgi Tunev
Telerik team
answered on 12 Mar 2008, 02:55 PM
Hi Bob,

The code seems fine - can you please make sure that the JavaScript is executed? You can do this by outputting a simple alert instead of calling the function
(e.g. closingScript ="<script type='text/javascript'>alert('test');</script> ")

If you still experience problems however, it will be best to open a support ticket and send us a small sample project which reproduces it. Please make sure that the project can be run and attach it to the support ticket along with a link to this thread - once I have a better look over your setup, I'll get back to you with solution right away.




Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 12 Mar 2008, 04:11 PM
Georgi,

I copied and pasted your code for the javascriot alert box but it does not appear when I run the web page.  Anything else I can try?  I don't think I will be able to send you a sample application because my client has several layers from different projects for things like data access and exception handling.  I am not familar with all the parts.

Thanks,
Bob
0
Georgi Tunev
Telerik team
answered on 13 Mar 2008, 12:15 PM
Hi Bob,

If the alert is not executed, this means that window.onload is not fired. Are you using Ajax? If this is so and you Ajaxify part of your page, it is possible that the script will not be loaded.

Please check the following KB article that shows how to output a Javascript code in several scenarios: http://www.telerik.com/support/kb/article/b454K-gtd-b454T-cec-b454c-cec.aspx - the KB article is about showing a radalert message, but the logic stays the same.

If you still experience problems however, I am afraid that you will need to send us some example on which we can work. It doesn't have to be your project, you can just isolate the problem itself in a separate one with 2 pages - one main page and a content one for the RadWindow. If you can reproduce the problem there, just send me that project and I will get back to you with solution right away.



Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 13 Mar 2008, 12:40 PM
You are right Georgi.  When I removed the AJAX manager control, it worked.  I will take a look at the article you sent.

Thanks again,
Bob
0
david
Top achievements
Rank 1
answered on 17 Mar 2008, 09:37 PM
Very cool, how do you do this: in 'C#' ?

thanks

Protected Sub Button4_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button4.Click 
    Dim closingScript As String 
    closingScript = "<script type='text/javascript'>window.onload = closeWin</script> " 
    ClientScript.RegisterStartupScript(Me.GetType(), "closeWin", closingScript) 
End Sub 
0
Georgi Tunev
Telerik team
answered on 18 Mar 2008, 06:33 AM
Hi David,

Here is the C# version of the code:
string closingScript;  
closingScript = "<script type='text/javascript'>window.onload = closeWin</script> ";  
ClientScript.RegisterStartupScript(this.GetType(), "closeWin", closingScript); 



Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JJ
Top achievements
Rank 1
answered on 18 Mar 2008, 08:03 PM
Can I get the same effect with my 'save and close' button within an UpdatePanel control?  It's in the UpdatePanel because I am changing it's visibility while editing other controls.

Right now my server-side code is executing but not the client-side.

Thanks,

JJ

0
Georgi Tunev
Telerik team
answered on 19 Mar 2008, 09:49 AM
Hello JJ,

Outputting a Javascript from a server-side code is a general task in ASP.NET / ASP.NET AJAX. Since I don't know your exact scenario, I cannot give you specific suggestions, but I would suggest to check the following KB article: (ID#673) Calling radalert from codebehind (RadWindow 1.x for ASP.NET) which discuss a similar scenario and offers several solutions.

If you still experience problems, please provide more details about your environment - e.g. how exactly do you update the page, the page's code, etc. This will give us more information on your setup and allow us to provide you with the appropriate suggestions.



All the best,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Anon
Top achievements
Rank 1
answered on 25 Jun 2008, 09:22 AM
Hi,

I'm using the code that you provided, however without the window close the button posts to the database. When I put in the window close code after my database code, it closes the windob but doesnot post to the database. Is there something that I am missing? My code reads exactly like that of the example.


thanks

Anon
0
Georgi Tunev
Telerik team
answered on 25 Jun 2008, 10:12 AM
Hello Anon,

Can you please open a support ticket and send me your implementation? I will check it and get back to you right away.



All the best,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Anon
Top achievements
Rank 1
answered on 26 Jun 2008, 11:58 AM

Hello Georgi,

Thank you for the quick response, however I figured it out. It was a browser problem. After posting here I began testing with IE (I tend to test first in Moz then IE), I found out it was posting correctly in IE. The fix was to put UseSubmitBehavior in the asp:button line to get Moz to post correctly. Thanks for the offer and keep up the good work!

-Anon

Tags
Window
Asked by
Bob
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Bob
Top achievements
Rank 1
david
Top achievements
Rank 1
JJ
Top achievements
Rank 1
Anon
Top achievements
Rank 1
Share this question
or