how the value of selected linkbutton can be pass to session...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pooja8389
    New Member
    • Sep 2010
    • 22

    how the value of selected linkbutton can be pass to session...

    sir in this code there is three linkbutton..the value(textvalue ) of selected linkbutton is write by abc function on that page.but i want to save this value in session..how can i do this ..plz tell me
    Code:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    
    public partial class exptlinkbtn : System.Web.UI.Page
    {
        SqlConnection  con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand com;
        LinkButton[] lbn=new LinkButton[4];
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lbn[i] = new LinkButton();
                lbn[i].ID = "lbn" + i;
                lbn[i].Text = "</br>"+"lbn" + i;
                lbn[i].CommandArgument = lbn[i].Text;
                lbn[i].Command += new CommandEventHandler(this.abc);
              
                form1.Controls.Add(lbn[i]);
    
    
            }
    
        }
    
        public void abc(Object sender, CommandEventArgs e)
        {
            Response.Write(e.CommandArgument);
        }
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    If you want to store something in session just do so.

    (vb.net)
    Code:
    Session("key") = "the value to be stored in session at the key provided"
    (c#)
    Code:
    Session["key"] = "the value to be stored in session at the key provided";
    When you need to access later do the following:
    (vb.net)
    Code:
    Dim valueRetrievedFromSession As String = Session("key")
    (c#)
    Code:
    String valueRetrievedFromSession = Session["key"];
    -Frinny

    Comment

    • pooja8389
      New Member
      • Sep 2010
      • 22

      #3
      plz tell me how can i do this in the above example at run time is i click on the lbl0 then the valuse is pass in the commandargument ...plz tell me how can i pass this value in a session..like
      Session["key"]=commandargumen t;
      plz solve this problem.
      Thanku

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I just told you what to do.
        I'm not sure I could explain it any more clearly....hmm maybe I can:

        In the method that you have implemented that handles the button click event......stor e the information into session.

        Then in the next page retrieve the information from session.

        It would be a lot easier to help you if you posted what you have tried so far along with an explanation of what is not working so that we can go from there.

        -Frinny

        Comment

        • pooja8389
          New Member
          • Sep 2010
          • 22

          #5
          i have many button which is dynamically created .i don't know the value of these button.at run time these button will create according to condition.then from there button i want to select one button and i want to use the text value of selected button on next pages or on other pages.so i want to pass the value(text value of selected button) in session.so plz tell me how can i do this.plz.plz

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Simply store the .Text property of the button in session.

            Code:
            Sessio["buttonText"] = theButtonInstance.Text
            In your case you have a bunch of button texts that you want to store...you can store an array or list of strings in session too:

            Code:
            List<string> buttonTexts = new List<string>();
            
            for (int i = 0; i < 3; i++)
            {
              lbn[i] = new LinkButton();
              lbn[i].ID = "lbn" + i;
              lbn[i].Text = "</br>"+"lbn" + i;
              buttonTexts.Add("</br>"+"lbn" + i);
            //  ...
            }
            Session["buttonTexts"] = buttonTexts;
            You should probably check out this article on How to use dynamic controls in ASP.NET. I think you're going to run into problems eventually if you keep using your current solution.

            -Frinny

            Comment

            • pooja8389
              New Member
              • Sep 2010
              • 22

              #7
              actually i don't know the value of the button.actually i m student and making i project on slambook.in this there is a page for frnd search on this page i fill the any name suppose pooja. then there is 5 frnds of this name.the id correspondance to that name show at the pageas link button text value then i select one from that value.if this value is stored in this then i can use this.plz tell me how can i do this..becoz i don't know how many id's are there.

              Comment

              • pooja8389
                New Member
                • Sep 2010
                • 22

                #8
                sir my problem is solved now thanku for reply.

                Comment

                Working...