chazbot7
chazbot7

Reputation: 596

Pass a URL variable to Javascript function using ASP.NET?

Basically, I'm trying to get ASP.NET to grab a variable out of the URL and use it to start a javascript function.

The user is viewing an online catalog (built with turn.js, a plugin for jquery), and when a page is clicked, it goes to a webpage with all the products from that catalog page on it. There's a link there back to catalog, but when you go back the catalog starts back at page 1. If I have the link include the page number in the URL (i.e. website.com/catalog.aspx?page=4) when you go back, I believe I can grab that out of the URL and use it to have the catalog turn to that page when it loads.

I usually stick to PHP, so I'm a bit lost here. I just need to write a little code snippet that will grab the page number and fire a javascript function using the number. Is this possible?

EDIT: Code:

Here's what I've got in javascript:

function changePage (pagenumber) {
    $("#flipbook").turn("page", pagenumber);
}

The page itself is run by NetworkSolutions, so I can't give you any of the actual code from the webpage. What I came up with so far from looking around the web is this (I hope I'm not doing this completely wrong):

<script runat="server">
    void Page_Load (object sender, EventArgs e) {
        var pagenumber = Response.QueryString['page'];
    }
</script>

I'm not sure if I'm getting the variable correctly, or even what to do with it after that to fire the javascript function. Thanks for any help given!

Upvotes: 1

Views: 2352

Answers (3)

Ronak Patel
Ronak Patel

Reputation: 2610

you can use server tags as below

function changePage (pagenumber) {
    $("#flipbook").turn("page", <%= Request.QueryString['page'] %>);
}

Upvotes: 2

Litash
Litash

Reputation: 182

Im using this plugin

Example:

To get the document params:

var value = $(document).getUrlParam("paramName");

To get the params of a html-attribut (uses src attribute)

var value = $('#imgLink').getUrlParam("paramName");

it works for me. Thanks the author.

Upvotes: 2

Vash The Stampede
Vash The Stampede

Reputation: 451

If I understand well your question, you want to grab the page number in the querystring using javascript, if that's correct, would this help?

How can I get query string values in JavaScript?

Upvotes: 2

Related Questions