Here are the steps that you will have to take:
In your code behind page:
private int _userId;
private int _courseId;
protected int CourseId
{
get { return _courseId;}
set { _courseId = value;}
}
protected int UserId
{
get { return _userId;}
set { _userId = value;}
}
Step 2 : based on your requirement now you have to set up those properties. The catch is that these properties should be set before they are referenced from the JavaScript. Maybe something like this in the Page_Load
event:
_userId = Session["userId"];
_courseId = Request.QueryString["CourseId"] != null ? Request.QueryString["CourseId"] : String.empty;
Of course you can parse them to appropriate types based on your requirements.
Finally, you can reference them in JavaScript as follows:
var currentUserId = '<% = UserId %>';
var currentCouseId = '<% = CourseId %>';
This should definitely work. I have used this approach many times.