我怎么给从ASP.NET变量的JavaScript变量的数据? [英] How do I give JavaScript variables data from ASP.NET variables?

查看:94
本文介绍了我怎么给从ASP.NET变量的JavaScript变量的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个符合SCORM API,用于我们的LMS和现在我使用硬codeD用户ID和courseID变量(引用的东西在数据库中的变量)。我需要通过真正的用户ID和courseID而不是使用硬codeD的人的。我知道用户ID存储在会议和courseID从启动页传过来。

I have created a SCORM API for our LMS and right now I am using hard coded userID and courseID variables (variables that reference things in the database). I need to pass the real userID and courseID instead of using hard coded ones. I know the userID is stored in the session and the courseID is passed over from the launch page.

我如何获得这些成JavaScript,所以我可以有他们在我来处理该SCORM调用ashx的电话?

How do I get these into JavaScript so I can include them in my calls to the .ashx that handles the SCORM calls?

推荐答案

也许最好的线最容易暴露他们作为你的页面的属性(或母版页,如果在每一页上使用),并通过页面引用它们指令。

Probably best easiest to expose them as properties of your page (or master page if used on every page) and reference them via page directives.

 <script type="text/javascript">
     var userID = '<%= UserID %>';
     var courseID = '<%= CourseID %>';

     .... more stuff....
 </script>

然后设定值上的Page_Load(或在Page_Load母版页)。

Then set the values on Page_Load (or in the Page_Load for the master page).

  public void Page_Load( object source, EventArgs e )
  {

        UserID = Session["userID"];
        CourseID = Session["courseID"];
        ...
  }

这篇关于我怎么给从ASP.NET变量的JavaScript变量的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆