I’m not very proud of this cause it indicates a very poor interface design, but in a legacy project I’m working on we had the following scenario:
1- the user interact on some elements of the UI
2- the user clicks a button, at the PostBack operation information are gathered about the UI status and what the user done on some elements
3- at the end of the processing we needed to open a popup showing the result of the operation.
The problem is: opening a popup is a client-side operation, while all the processing is done server-side.
You do that using the Page.ClientScript.RegisterStartupScript() call, but this one will not work if you try to use it inside an Ajax UpdatePanel; to solve the problem you have to use the ‘new’ ScriptManager.RegisterStartupScript() call, here’s an example:
Public Function CreateWindowsOpenFunction(ByVal link As String) As String
link = Navigation.AdjustLinkForVirtualPath(link)
Private Sub OpenInAnotherWindow(byval url as string)
Dim script As String = CreateWindowsOpenFunction(url)
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "navigation", script, True)
You can call the OpenInAnotherWindow() function at the end of your processing, when the page will be reloaded by the browser (after the PostBack) the window.open() script will be executed.
By the way, in the example above I used GetType() as the second argument of the call, but you really should avoid doing it, take a look at this post: Don't use GetType() with Page.ClientScript.RegisterClientScriptBlock()
If you have to start using tricks like these, maybe it’s better to start rethinking the UI and the data flow of your application.