how to pass a complicated string through url querystring

Posted on 2011-05-05
Last Modified: 2012-05-11
I dynamically added a Hyperlinkcolumn to a  arraylist and the array list will be added to datagrid.:

                        tempHyperLink1 = new HyperLinkColumn();
                        tempHyperLink1.DataTextField = infoTemp.DisplayName;
                        tempHyperLink1.DataTextFormatString = "<img alt=\"Update something\" style=\"border:0\"  src=\"../Images/update.jpg\" />";
                        tempHyperLink1.DataNavigateUrlField = infoTemp.DisplayName;
                        tempHyperLink1.DataNavigateUrlFormatString = "~/anotherFolder/NextPage.aspx?s={0}";
                        tempHyperLink1.HeaderText = "something";

But the problem is that {0} is composed of very complicated string and make the url invalid.How to deal with it? I want ot use {0} in the next page. There is no way to create a session variable since it's dynamic. Appreciated for your idea!!!!
Question by:jssong2000

    Author Comment

    urlencode make the string too long.....

    Author Comment

    Actually it's no way to make a url encode since it's dynamic. So you can't make it like:

    tempHyperLink1.DataNavigateUrlFormatString = "~/anotherFolder/NextPage.aspx?s=" + Server.UrlEncode("{0}");
    It will encode these symbols {0}
    LVL 30

    Expert Comment

    You could change the Hyperlinkcolumn into a templatecolumn, add a hyperlink, and then find the Hyperlink in the databound method, then format the string and assign it a value there...
    Public Sub myGrid_Bound(sender As Object, e As DataGridItemEventArgs) Handles myGrid.ItemDataBound
        if e.Item.ItemType = ListItemType.Item or e.Item.ItemType = ListItemType.AlternatingItem then
            Dim myHyperlinkAs Hyperlink = CType(e.item.cells(1).FindControl("myHyperlink"), Hyperlink )
            if myHyperlink isnot nothing then myHyperlink.NavigateUrl = "~/anotherFolder/NextPage.aspx?s=" & Server.UrlEncode("{0}")
        end if
    end sub

    Open in new window

    LVL 30

    Accepted Solution

    An even better approach would be to perhaps find another key value to use in the querystring, say an integer, but one that would still allow you to retrieve the required string value on NextPage.aspx.
    LVL 5

    Expert Comment

    request length can be 2k, post length can be 8k.

    change request length in the iis config or send the url in post, not in the url.

    Author Comment

    MlandaT - I tried to add another key in the table. But the table will be updated everyweek. So the id may be different in two tables as usually PK and FK relationship.

    dexion432- Could you please explain a little detail? Thanks!!!!

    My page's content is:
    <%@ Register Src="~/Controls/QuerySpecification.ascx" TagName="SearchSpecification" TagPrefix="Custom" %>
    <%@ Register Src="~/Controls/SearchResultsGrid.ascx" TagName="SearchResults" TagPrefix="Grid" %>
    <asp:Content ContentPlaceHolderID="head" ID="headerInfo" runat="server">
    <asp:Content ContentPlaceHolderID="bodyContent" ID="cBody" runat="server">
      <Custom:SearchSpecification ID="cntrlSearchSpecs" runat="server"></Custom:SearchSpecification>
         <Grid:SearchResults ID="cntrlSearchResults" DisplayNumber="50" runat="server" Visible="false">

    datagrid is in cntrlSearchResults

    Author Comment


    what is c# for your
     Dim myHyperlinkAs Hyperlink = CType(e.item.cells(1).FindControl("myHyperlink"), Hyperlink )? Thanks!!!

    Author Closing Comment

    This is helpful. Thanks!!!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now