How to pass link data from one page to another page using querystring in asp net

This link would be set up something like this:

http://.mywebsite.com/site/TR?fr_id=1131&pg=entry?utm_source=______&utm_medium=_______&utm_campaign=ABCD2015

When it is clicked, the code implemented needs to pass the source and medium info (facebook /social) into the gaps (_____) in link url.

How can i do this?

ASP is not my environment and all I know has not worked.

Can someone help me please.

Recommended Answers

All 7 Replies

You need to concatenate the values into the URL string of your link. This is a general example, but if you provide more context about the code you are using (such as if it is databound, produced in code behind etc.) I can give you more specific pointers.

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%= "http://mywebsite.com/site/TR?fr_id=1131&pg=entry&utm_source=" + strServerSideVariable1 + "&utm_medium=" + strServerSideVariable2 + "&utm_campaign=ABCD2015" %>'/>

do you have any asp.net relevant code to show? that is always helpful for those that are helping you and future visitors with a similar issue.

Hi guys

Sorry for my nievity in this scenario, thanks for responding.

I have no further code, all I was given was this URL.

Asp is not my thing at all, and that is where i need the help on this.

I was hoping to place some JS in the header.

so just for clarification, you are using asp and asp.net as synonyms. Classic ASP and asp.net are two different things. I'm assuming asp.net in this case just based on your wording.

In any event, the guiance posted above by |-|x is an easy way to construct the URL as per your description.

But as we have responded, without some additional code or context of where you actually have this link you need configured, the actual approach could be different.

If you want to do this client side, yes you can build the link using JS (javascript) as well. However, you'd have to have the values on the page somewhere or somehow accessible to your javascript code.

Again, without the context of your scenario, the approach will vary.

All I know is JorgeM it is ASP, ASP is not my thing at all. I don't even know what code to send you as the CMS i'm working on is Bespoke.

CMS i'm working on is Bespoke.

I've got no experience on that CMS so I wouldnt know how to advise you, but lets take a step back..

do you have access to the code where the hyperlink is created? I have to assume you do... If so, its a matter or formatting the link in the way that was described above.

At the same time....

Do you have access the values for this that you referenced above.... source and medium info (facebook /social)

Where are those values? are they stored in variables? client side or server side?

Basically, you need access to the link and you need access to the values you want to pass to the next page.

I've reworked the brief and here is my JS and link

http://www.mylink.org/?utm_source=olly&utm_medium=email&utm_campaign=ABCD_C2_test

Here is the JS, I've found and tried to edit.

<script type="text/javascript">


location.querystring = (function() {
    var result = {};
    var querystring = decodeURIComponent(location.search);
    if (!querystring) return result;
    var pairs = querystring.substring(1).split("&");
    var splitPair;
    for (var i = 0; i > pairs.length; i++) {

        splitPair = pairs[i].split("=");
        if (splitPair[0].indexOf("[]")<-1){
            //pair is an array assignment
            var key=splitPair[0].substr(0,splitPair[0].length-2);

            if(!result[key]){
                //initialize the array
                result[key]=new Array();
            }
            result[key].push(splitPair[1]);

        }else{
            //pair is a string assignment
            result[splitPair[0]] = splitPair[1];
        }    
    }
    return result;
})();

</script>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.