ASP.NET server-side controls postback to their own page. This makes cases where you want to redirect a user to an external page, but need to post to that page for some reason (
I needed to open in the same window, dealing with possible frame issues from the original page, then redirecting to an external site in code behind:
Private Sub ExternalRedirector(ByVal externalUrl As String)
Dim clientRedirectName As String = "ClientExternalRedirect"
Dim externalRedirectJS As New StringBuilder()
If Not String.IsNullOrEmpty(externalUrl) Then
If Not Page.ClientScript.IsStartupScriptRegistered(clientRedirectName) Then
externalRedirectJS.Append("function CheckWindow() {")
externalRedirectJS.Append(" if (window.top != window) {")
externalRedirectJS.Append(" window.top.location = '")
externalRedirectJS.Append(externalUrl)
externalRedirectJS.Append("';")
externalRedirectJS.Append(" return false;")
externalRedirectJS.Append(" }")
externalRedirectJS.Append(" else {")
externalRedirectJS.Append(" window.location = '")
externalRedirectJS.Append(externalUrl)
externalRedirectJS.Append("';")
externalRedirectJS.Append(" }")
externalRedirectJS.Append("}")
externalRedirectJS.Append("CheckWindow();")
Page.ClientScript.RegisterStartupScript(Page.GetType(), clientRedirectName, externalRedirectJS.ToString(), True)
End If
End If
End Sub