473,480 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

22 New Member
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
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using System.Data.SqlClient;
  14.  
  15. public partial class exptlinkbtn : System.Web.UI.Page
  16. {
  17.     SqlConnection  con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  18.     SqlCommand com;
  19.     LinkButton[] lbn=new LinkButton[4];
  20.     protected void Page_Load(object sender, EventArgs e)
  21.     {
  22.         for (int i = 0; i < 3; i++)
  23.         {
  24.             lbn[i] = new LinkButton();
  25.             lbn[i].ID = "lbn" + i;
  26.             lbn[i].Text = "</br>"+"lbn" + i;
  27.             lbn[i].CommandArgument = lbn[i].Text;
  28.             lbn[i].Command += new CommandEventHandler(this.abc);
  29.  
  30.             form1.Controls.Add(lbn[i]);
  31.  
  32.  
  33.         }
  34.  
  35.     }
  36.  
  37.     public void abc(Object sender, CommandEventArgs e)
  38.     {
  39.         Response.Write(e.CommandArgument);
  40.     }
  41.  
  42.  
Oct 7 '10 #1
7 2439
Frinavale
9,735 Recognized Expert Moderator Expert
If you want to store something in session just do so.

(vb.net)
Expand|Select|Wrap|Line Numbers
  1. Session("key") = "the value to be stored in session at the key provided"
(c#)
Expand|Select|Wrap|Line Numbers
  1. Session["key"] = "the value to be stored in session at the key provided";
When you need to access later do the following:
(vb.net)
Expand|Select|Wrap|Line Numbers
  1. Dim valueRetrievedFromSession As String = Session("key")
(c#)
Expand|Select|Wrap|Line Numbers
  1. String valueRetrievedFromSession = Session["key"];
-Frinny
Oct 7 '10 #2
pooja8389
22 New Member
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"]=commandargument;
plz solve this problem.
Thanku
Oct 8 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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......store 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
Oct 8 '10 #4
pooja8389
22 New Member
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
Oct 8 '10 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Simply store the .Text property of the button in session.

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. List<string> buttonTexts = new List<string>();
  2.  
  3. for (int i = 0; i < 3; i++)
  4. {
  5.   lbn[i] = new LinkButton();
  6.   lbn[i].ID = "lbn" + i;
  7.   lbn[i].Text = "</br>"+"lbn" + i;
  8.   buttonTexts.Add("</br>"+"lbn" + i);
  9. //  ...
  10. }
  11. 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
Oct 8 '10 #6
pooja8389
22 New Member
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.
Oct 8 '10 #7
pooja8389
22 New Member
sir my problem is solved now thanku for reply.
Oct 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
12062
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
3
1554
by: Diffident | last post by:
Hello All, I want to display all the name-value pairs of the session object....how can I print them out? i.e., suppose once a user logs in I set a session variable login time Session = "2pm" and...
4
2551
by: riteshjain82 | last post by:
Hi, I am maintaining a site which is written in ASP. Now i have to create some new pages. In one page we have a table with many rows. Now, I want to enable or disable(showing and hiding also) 2...
1
1461
by: vishnu | last post by:
Hi, I have a fully editable datagrid which has dropdownlist in two columns. Now i have to bind the dropdown in the second column based on the value selected in the dropdown in the firstcolumn. so...
0
1066
by: planetthoughtful | last post by:
Hi All, I have a c# web form that has two listviews on it. Both currently retrieve their list entries from two separate tables in an SQLServer backend. I've been asked to make the values in the...
3
1533
by: settyv | last post by:
Hi, I need to generate PDF stream when i click on Linkbutton in datagrid ..At present i hardcoded the DMS Id and now it is working.But i need to pass DMS ID when click linkbutton.How can i do...
1
2384
by: prashu | last post by:
how to retrieve a value selected in a drop down list box using jsp
3
4747
by: hon123456 | last post by:
Dear all, I have a session variable session("loginid) which can be passed from A.asp to B.asp. Then In B.asp I have a hyperlink to C.asp e.g. < A href..C.asp>. The session variable cannot be...
2
1923
by: gamernaveen | last post by:
Why do people pass session ids in URLs? (GET method) I mean whats the use? ex. sample.php?sid=<sessionid> Doesnt it work without passing ?
1
1927
by: visweswaran2830 | last post by:
Hi, I have four cascading dropdown control and now I want to load a gird data based on the value selected on that dropdown. This should be done by using ajax concepts..
0
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.