DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Passing unicode query string to popup window using window.open method (http://www.daniweb.com/forums/thread196881.html)

ypdev Jun 10th, 2009 9:50 am
Passing unicode query string to popup window using window.open method
 
Hi,

I am trying to pass query string from one page to popup window as follow:

Dim popupScript As String = "window.open('cFinder.aspx?cName=" & c_TextBox.Text & "','', 'width=420,height=200,menubar=no,scrollbars=yes');"
If (Not Page.ClientScript.IsStartupScriptRegistered("popup")) Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "popup", popupScript, True)
End If

The popup window comes up very well only if the text I typed is in english. otherwise the popup window comes up empty and the string I see in the "view source" option (in IE) is "%ufffd%%ufffd...."

I will need to query some unicode characters.

Any idea?

Thanks.

adatapost Jun 10th, 2009 11:54 am
Re: Passing unicode query string to popup window using window.open method
 
IE - User interface uses UTF-8 character set.

ypdev Jun 11th, 2009 5:19 am
Re: Passing unicode query string to popup window using window.open method
 
I understand but when I redirect the query response to anotherpage.aspx instead of "popup" (window.open) it works fine and the string is as I typed it.

I am trying to understand what is the diff. between popup and standard page in terms of encoding.

Anything I missing in my code?

ypdev Jul 5th, 2009 10:23 am
Re: Passing unicode query string to popup window using window.open method
 
For those who needs the same solution:

I found a VB function that "convert" 'response.redirect' to popup window...

    Public Sub Redirect(ByVal url As String, ByVal target As String, ByVal windowFeatures As String)
        Dim context As HttpContext = HttpContext.Current
        If ([String].IsNullOrEmpty(target) OrElse target.Equals("_self", StringComparison.OrdinalIgnoreCase)) AndAlso [String].IsNullOrEmpty(windowFeatures) Then
            context.Response.Redirect(url)
        Else
            Dim page As Page = DirectCast(context.Handler, Page)
            If page Is Nothing Then
                Throw New InvalidOperationException("Cannot redirect to new window outside Page context.")
            End If
            url = page.ResolveClientUrl(url)
            Dim script As String
            If Not [String].IsNullOrEmpty(windowFeatures) Then
                script = "window.open(""{0}"", ""{1}"", ""{2}"");"
            Else
                script = "window.open(""{0}"", ""{1}"");"
            End If
            script = [String].Format(script, url, target, windowFeatures)
            ScriptManager.RegisterStartupScript(page, GetType(Page), "Redirect", script, True)
        End If
    End Sub


And in the btnSubmit sub:

            Session.Item("ObjToRedirect") = TextBox1.Text
            Redirect("NextPage.aspx", "_blank", "width=200,height=200,menubar=no,scrollbars=yes")

Of course, you'll have to translate the session item on NextPage.aspx if you need to make a query.

Enjoy...


All times are GMT -4. The time now is 2:37 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC