如何创建会话onclick的超链接?

时间:2013-10-21 05:16:09

标签: asp.net

我创建了一个页面。其中有2个菜单。一个用于通过学生,另一个用于失败学生。单击通过学生显示studentid,rollno,batch和grid.Grid列中的所有主题列表是动态更改的。 失败学生的onclick只显示rollno,批处理和失败的主题。 Inrowbound事件动态地为学生传递超链接到学生。点击超链接,新窗口打开。所以我以查询字符串的形式通过studentid获取所选学生的所有细节并隐藏窗口工具栏.Admin可以修改该记录。我使用了studentid以qurystring的形式。我想在session中使用该值。我怎么能这样做? 在rowbound事件中,我添加了这样的

if(e.Rows.Cell.Count == 6)
{
 Hyperlink hy = new hyperlink();
 e.Row.Cell[0].Controls.Add(hy);
 hy.Attributes.Add("Onclick","Return showdetail('"+e.Row.cell[0].Text+"')")
}

//在aspx页面 - 在javascript中

<script type = "text/javascript">
showdetail(Studentid)
{
  Window.Open("samplepage.aspx?id="+Studentid+","win32","toolbar=no,resizeable=1");
}
</script>

2 个答案:

答案 0 :(得分:1)

<script type = "text/javascript">
showdetail(Studentid)
{
<%=Session["sid"]=Studentid %>
  Window.Open("samplepage.aspx?id="+Studentid+","win32","toolbar=no,resizeable=1");
}
</script>

答案 1 :(得分:0)

你需要进行ajax调用。为简单起见,我在这里使用jquery文件。只需要在标题部分中包含jquery.1.9.1.js,然后您可以修改showdetail函数,如下所示

在ASPX / JS中调用AJAX

Showdetail(Studentid)
{
      $.ajax({
               type: "POST",
                url: "Home.aspx/AssignSession",
                data: "{'stdid':'" + Studentid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(res) {
if(res.d=="Success")
                      window.Open("samplepage.aspx","win32","toolbar=no,resizeable=1");
                }
            });

代码背后的方法

 [WebMethod]
        public static string AssignSession(string stdid)
        {
HttpContext.Current.Session["stdid"]=stdid;
return "Success";
    }

现在,您可以在应用程序中的任何位置(samplepage.aspx)访问此会话变量Session["stdid"]。这符合您的要求。