在asp.net页面之间传递值

时间:2012-04-10 09:28:35

标签: c# javascript asp.net

我在EnterSession.aspx.cs中有这段代码

[System.Web.Services.WebMethod]
            public static string GetSessionName(string session_name, int SessionId)
            {
                string result = "";
                try
                {
                    SqlConnection thisConnection = new SqlConnection(@"data Source=ZOLA-PC;AttachDbFilename=D:\2\5.Devp\ASPNETDB.MDF;Integrated Security=True");
                    thisConnection.Open();
                    SqlCommand thisCommand = thisConnection.CreateCommand();
                    thisCommand.CommandText = " SELECT session_name FROM myApp_Session WHERE session_id = @SessionId;";
                    thisCommand.Parameters.AddWithValue("SessionId", SessionId);
                    SqlDataReader thisReader = thisCommand.ExecuteReader();
                    while (thisReader.Read())
                    {
                        result = thisReader["session_name"].ToString();
                    }
                    thisReader.Close();
                    thisConnection.Close();
                    return result;
                }
                catch (SqlException ex)
                {
                    return ex.Message;
                }
            }

然后我在EnterSession.aspx页面

中使用了这些代码
gaq.push(['pageTrackerTime._trackEvent', 'Fancy Running Session', document.getElementById('session_name').value, document.location.href, roundleaveSiteEnd]);

代码的另一部分是

 <input type="hidden" id="session_name" />
<script type="text/javascript">
    document.getElementById('session_name').value = '<%= this.SessionName %>';
</script>

背后的想法是根据从上一页传递的session_id从数据库中获取session_name,并使用get element by id将其传递给Google分析服务器。

这个实现对我不起作用,哪里可能是我的错?提前谢谢

0 个答案:

没有答案