Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Server.UrlEncode
Message
 
 
To
14/01/2008 13:38:04
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01281652
Message ID:
01281663
Views:
6
>>Hi everybody,
>>
>>How can I find out what Server.UrlEncode is supposed to do?
>>
>>The code is creating a QueryString which includes title for the page. When I put ' in the title the website blows up and gives me an error "expected ;" from the JavaScript which brings me to the wrong QueryString.
>>
>>I'm not sure how can I fix this problem to allow typing anything in the Title?
>>
>>This is not actually the problem I have to fix, but since I found it, I want to fix it as well.
>>
>>I'm also wondering where can I ask questions regarding fckEditor? I tried their forum but didn't get many responses so far...
>>
>>Thanks a lot in advance.
>
>As far as your first question, Server.UrlEncode transforms a querystring to properly formatted URL specifications. I use it for all of my URLs that use querystring. Are you including the entire URL in the method, or just the querystring section? Here is an example from my Webform Base class.
>
>    Protected Sub NavigateTo(ByVal location As String, _
>                                Optional ByVal parms As NameValueCollection = Nothing)
>
>        Dim link As New StringBuilder
>
>        link.Append(Me.VirtualRoot)
>        link.Append(location)
>
>        If Not parms Is Nothing Then
>            link.Append("?")
>            For i As Integer = 0 To parms.Count - 1
>                link.Append(Server.UrlEncode(parms.Keys.Get(i)) & "=" & Server.UrlEncode(parms(i)))
>                link.Append("&")
>            Next
>            'Remove the last "&"
>            link.Remove(link.Length - 1, 1)
>        End If
>
>        Response.Redirect(link.ToString)
>
>    End Sub
>
Hi Mike,

Thanks a lot for your response.

As I see, the code tries to generate a QueryString inside the JavaScript, e.g.
 string strRedirect;
            strRedirect = "<script language='Javascript'>";
            strRedirect += "parent.frames['mainFrame'].location.href='pagedetails.aspx?wid=";
            strRedirect += Server.UrlEncode(WID.ToString()) + "&nid=" + XmlConvert.EncodeName(newurl.Substring(newurl.LastIndexOf("/") + 1)) + "&url=" + newurl + "&pid=" + Server.UrlEncode(newpid) + "&title=" + Server.UrlEncode(newtitle) + "';";
            strRedirect += "parent.frames['leftFrame'].location.href='editpages.aspx?wid=";
            strRedirect += Server.UrlEncode(WID.ToString()) + "&nid=" + XmlConvert.EncodeName(newurl.Substring(newurl.LastIndexOf("/") + 1)) + "&url=" + newurl + "&pid=" + Server.UrlEncode(newpid) + "';";
            strRedirect += "alert('Page Added Successfully');</script>";
            Response.Write(strRedirect);
            Response.Flush();
Now, the problem is with the newTitle. How can I allow & and ' inside it?

In JavaScript the ' should be replaced with \', however simply replacing newtitle doesn't work.

Do you have ideas how can I solve this problem?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform