Automatic URL Encoding?

7 posts, 1 answers
  1. Augusto
    Augusto avatar
    9 posts
    Member since:
    Sep 2009

    Posted 09 Mar 2010 Link to this post

    Hello,

    I have a lot of Grids that display correctly strings from a database that contains Chinese and Japanese characters as well as German and French accents. I have to build links from this items in the Grids to display the details in another page.

    The URL passed to the new page has the Chinese/Japanese/etc characters: http://test.aspx?Os=Microsoft Windows 7 旗舰版

    Because the way IE works I need this URL to be encoded or when I read back the Os variable it will return the value Microsoft Windows 7 ????.

    I know I can accomplish this via the following Sub:

    Protected Sub MyGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles MyGrid.ItemDataBound  
            If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then 
                Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
                Dim currentRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)  
                For Each col As GridColumn In RadgridWinServerOSCount.Columns  
                    If col.UniqueName = "columnOS" Then 
                        Dim strTxt As String = currentRow.Row("Operating_System").ToString  
                        Dim NewUrl As String 
                        NewUrl = Server.UrlEncode(strTxt)  
                        CType(dataItem("columnOS").Controls(0), HyperLink).NavigateUrl = "~/test.aspx?Os=" & NewUrl  
                    End If 
                Next 
            End If 
        End Sub 

    However this is kind of unpractical as the application I'm handling have around 25 different Grids where this needs to be changed, hence, even by creating a function to re-write the URL it's going to require a lot of code and the maintenance would be too cumbersome.

    I was wondering if there's a way to "automatically" URL encode the GridHyperLinkColumn items in the Grid, I looked throught the documentation but I couldn't find anything relevant. I think to optionally allow this encoding for GridHyperLinkColumn would be really handy.

    Thanks!
  2. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 12 Mar 2010 Link to this post

    Hi Augusto,

    Such a feature is not available in the hyperlink column of RadGrid and I am afraid the code-behind solution is the only one available.

    Regards,
    Tsvetoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Augusto
    Augusto avatar
    9 posts
    Member since:
    Sep 2009

    Posted 12 Mar 2010 Link to this post

    Thanks Tsvetoslav,

    I suspected that. Will it be possible for you guys to consider adding a feature for RadGrid to enable URL encoding as an option? It will be a great addition for those people that need Japanese, Chinese, Cirilyc language sets and use IE.

    Thanks,

    Augusto.
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 17 Mar 2010 Link to this post

    Hi Augusto,

    Unfortunately, for the time being our development team has deemed it not necessary to implement such a feature. However, if more customers express an interest in it we will give it due consideration.

    Regards,
    Tsvetoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Tyson
    Tyson avatar
    9 posts
    Member since:
    Apr 2007

    Posted 28 Jan 2013 Link to this post

    You can also try inheriting from the GridHyperlinkColumn

    I'm trying something along these lines. Haven't started testing yet, so we'll see how it goes...

    public class GridEncodableHyperlinkColumn : GridHyperLinkColumn {
     
            public bool URLEncodeLinks { get; set; }
     
            public GridEncodableHyperlinkColumn() : base() {
                URLEncodeLinks = true;
            }
     
            protected override string FormatDataNavigateUrlValue(object[] dataUrlValues) {
                if (URLEncodeLinks) {
                    for (int i = 0; i < dataUrlValues.Length; i++ ) {
                        if (dataUrlValues[i] != null && dataUrlValues[i] is string && !string.IsNullOrEmpty((string)dataUrlValues[i])) {
                            string dataUrlValue = HttpContext.Current.Server.UrlEncode((string)dataUrlValues[i]);
                            dataUrlValues[i] = dataUrlValue;                     
     
                        }
                    }
                }
     
                return base.FormatDataNavigateUrlValue(dataUrlValues);
            }
        }

    ...then just use that instead of the GridHyperLinkColumn.
  7. John
    John avatar
    6 posts
    Member since:
    Jun 2013

    Posted 04 Jul 2013 Link to this post

    Hi, is it still the case that in the latest version of the GridHyperLinkColumn it does not URL encode the DataNavigateUrlFields, so I have to do this myself manually eg in code behind?

    If so, please consider adding this capability as it is rather clumsy to do manually when the whole point of the DataNavigateUrlFields and DataNavigateUrlFormatString properties is for the control config to be 100% declarative.

    Thanks
  8. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 09 Jul 2013 Link to this post

    Hello John,

    This feature is not on our to-do list. Please, share your feedback at:
    http://www.telerik.com/feedback.aspx
     
    Regards,
    Tsvetoslav
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017