errors with opening URL in asp.net
I have the following asp:HyperLink which opens in ColorBox:
<asp:HyperLink id="HyperLink2" runat="server" Text="Delete" class="example7" ToolTip="Delete this Album" NavigateUrl='<%# "delete_album_confirm.aspx?AlbumName=" & Eval("album_name") & "&PhotoFilename=" & Eval开发者_开发问答("photo_file_name") & "&AlbumID=" & Eval("album_id") %>'></asp:HyperLink>
The above works fine if the Eval("album_name")
is without space. The problem is when i have spaces the colorBox doesn't open. For example:
delete_album_confirm.aspx?AlbumName=testing album cover&PhotoFilename=resized_CIMG1426.jpg&AlbumID=41
Can anyone tell me how I can use spaces and still get this working?
Any help would be much appreciated.
Thanks
The problem is probably that spaces are not allowed in URLs, so what you would need to is use Url Encoding. You should be able to accomplish that like this:
<asp:HyperLink id="HyperLink2" runat="server" Text="Delete" class="example7" ToolTip="Delete this Album" NavigateUrl='<%# HttpUtility.UrlEncode("delete_album_confirm.aspx?AlbumName=" & Eval("album_name") & "&PhotoFilename=" & Eval("photo_file_name") & "&AlbumID=" & Eval("album_id")) %>'></asp:HyperLink>
Replace your spaces with the URL encoded equivalent, %20
. e.g.
delete_album_confirm.aspx?AlbumName=testing%20album cover&PhotoFilename=resized_CIMG1426.jpg&AlbumID=41
精彩评论