We help IT Professionals succeed at work.
Get Started

open.window from codebehind

4,907 Views
Last Modified: 2012-05-11
I've seen several solutions to doing this but I have yet to get one to work...

I have a website that I'm trying to get (from login) to open a web application in a new window. Once the user logs in and gets validated I set some session variables and then choose the page the user goes to based on their security level. If I use the response.redirect() then it works fine... just doesn't open in a new window but my point is that I know the user is being validated. But if I try to call the javascript (or build the javascript) from codebehind it immediately takes the app to the logout screen.

Here is the last piece of code I tried
        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
        sb.Append("<script language='javascript'>")
        sb.Append("window.open('webapp.aspx', '', 'resizable=yes, menubar=no, toolbar=no,   status=no, location=no, channelmode=yes')<")
        sb.Append("/script>")

        If Not ClientScript.IsClientScriptBlockRegistered(Me.GetType(), "PopupScript") Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "openPopUp", sb.ToString())
            'ClientScript.RegisterStartupScript(Me.GetType(), "openPopUp", sb.ToString())
            'Response.Write(sb.ToString())
        End If

Open in new window



you can see I have tried a couple different methods... I've tried several others also including this one.
codebehind
Dim url As String = "~/webapp.aspx"
        ClientScript.RegisterStartupScript(Me.GetType(), "openwin", "<script>openPopUp2('" & url & "')</script>")

aspx
function openPopUp2(url) {
            alert('hi');
            window.open(url, "", " resizable=yes, menubar=no, toolbar=no, status=no, location=no, channelmode=yes");
        }

Open in new window


I put the alert in there just to see if it was even hitting the javascript code and it is not... not sure what to try next.

thanks
Comment
Watch Question
Full Stack .NET Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 18 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE