You must Sign In to post a response.
  • Category: ASP.NET

    How to create session onclick of hyperlink?


    Read this thread to know, how to create a Session while clicked a HyperLink control?



    I have created one page.In that there are 2 menu.One for pass student and other for fail student.Onclick of pass student shows studentid,rollno,batch and all subject list in grid.Grid column are dynamically changes.
    Onclick of fail student just displaying rollno,batch and fail in which subject.
    Inrowbound event dynamically added hyperlink to studentid for pass student.Onclick of hyperlink,new window get opened.So I passed studentid in form of querystring for fetching all detail of selected student and hide toolbar of window.Admin can modify that record.I used studentid in the form of qurystring.I want to use that value in session.How can I do that?In rowbound event I added like this

    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+"')")
    }
    // In aspx page -- In javascript

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

    You can add session at any event using below code.

    For your case,

    Session["StudentID"] = e.Row.cell[0].Text;


    All the Best.

    -------------
    Glad to be,
    John Bhatt
    Editor - DNS Forums
    https://www.pyarb.com

  • #731162
    Hi,

    As per your post you need to pass parameters based on LinkButton click event into another page right for this just refer below sample code.

    Source Code


    <asp:LinkButton ID="lblTitle" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' CommandName="Edit" CausesValidation="false" />


    and in RowCommand event of gridview you just perform your action


    Protected void GV_OnRowCommand(object sender,GridViewCommandEventArgs e)

    {
    if(e.CommandName=="View")
    {
    if(e.Row.RowType==DataControlRowState.DataRow)
    {
    Id = Convert.ToInt32(((Label)e.Row.FindControl("lblId")).Text);
    Val = ((LinkButton)e.Row.FindControl("lblVal")).Text;

    }
    Response.Write("<script language='javascript'>window.open('" + "page.aspx?Id=" + Id + "&Value=" + val + "',null,'toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width=1100px,height=700px');</script>");
    }
    }


    Hope this will help you to resolve the issue..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #731163
    Thanks John,for ur reply.If I will write this code in rowbound event,it will take grid's last column value in session.I don't want to do that.I want to take value of studentid which is clicked in session.

  • #731861
    HI,

    You can assign session to store the user data.


    Try the following modified code of yours
    In showdetail no need to pass the studentid querystring because you are storing in session which you can fetch in another page by referring the saved session.


    if(e.Rows.Cell.Count == 6)
    {
    Hyperlink hy = new hyperlink();
    e.Row.Cell[0].Controls.Add(hy);
    //Following code is the storing of session named Studentid
    Session["Studentid"] = e.Row.cell[0].Text;
    hy.Attributes.Add("Onclick","Return showdetail()")
    }
    // In aspx page -- In your javascript there will not any query string only you are passing the samplepage.aspx filename.

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



    In pageload of the samplepage.aspx page you can fetch the stored session Studentid like the following code.


    protected void Page_Load(object sender, EventArgs e)
    {
    //Following code to fetch the session Studentid and assign it to the studentid string variable.

    string studentid = Session["Studentid"].ToString();

    }



    Hope it will be useful.

    Regards,
    T.N. THEAAVARAAJ
    Senior Software Engineer,
    Microsoft Certified Technology Specialist.
    Email:devabe2005@gmail.com


  • Sign In to post your comments