• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

how to pass a complicated string through url querystring

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!!!!
  • 5
  • 2
1 Solution
jssong2000Author Commented:
urlencode make the string too long.....
jssong2000Author Commented:
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}
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
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.
jssong2000Author Commented:
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
jssong2000Author Commented:

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now