views:

55

answers:

1

Hi guys, I have this piece of code in javascript:

 var catId = $.getURLParam("category");

In my asp.net and c# code for "category" query string i use a public const:

public const string CATEGORY = "category";

so if i want to change the query string parameter to be "categoryTest" i only change this const and all the code is updated.

Now the question is: how can i do something similar for the javascript i have in the same application (so i want to use the same constant)?

I mean i want something like this:

var catId = $.getURLParam(CQueryStringParameters.CATEGORY);

but because there are none asp.net tags, my const is not interpreted...

Any workaround?

+3  A: 

Declare a global variable in your aspx page:

<script type="text/javascript">
var categoryParam = '<%= CQueryStringParameters.CATEGORY %>';
</script>

And then use this global variable in your javascript file:

var catId = $.getURLParam(categoryParam);
Darin Dimitrov
Thanks a lot! It works ;)
Cristian Boariu