|
-
Jun 24th, 2007, 09:50 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Can I get an idea on how to pass info, trying session but having problems
I have this data taken from the database. At first I had the relatives name as a link in a label and realized I was going to have difficulty trying to pass along session data to the next page that related to the link as it wasn't like a linkbutton that I could handle a clicking event. So, I tried to add a linkbutton inbetween the two labels of that data. I now create a session variable when the linkbutton is clicked. But the problem is I can't figure out how to pass along which relative was clicked. Since I am going through the database of relatives, what ends up happening is that the last person in the database ends up being the name that gets put into the session variable.
I hope someone can show me a way to resolve this so that the right name gets passed into the session variable for using on the next page.
Thanks so much in advance.
Here is what I tried first:
Code:
while (reader.Read())
{
//Don't print out the hr before the first relative
if(cntr != 1)
Label4.Text += "<hr />";
Label4.Text += "<strong>" + reader["Relation"].ToString() + "</strong>" + ": ";
//See this relatives relations
Label4.Text += "<a href=\"searchrelatives.aspx\">" + reader["RelativeFN"].ToString() +
" " + reader["RelativeLN"].ToString() + "</a>" + "<br />";
//create session variable to pass along who the relative is
Session["ChosenRelative"] = reader["RelativeFN"].ToString() + reader["RelativeLN"].ToString();
if (reader["RelativeBP"].ToString() != "")
Label4.Text += "Birth Place: " + reader["RelativeBP"].ToString();
if (reader["RelativeEmail"].ToString() != "")
Label4.Text += " | e-Mail: " + reader["RelativeEmail"].ToString();
if (reader["RelativeIM"].ToString() != "")
Label4.Text += " | Instant Messenger Handle: " + reader["RelativeIM"].ToString() + "<br />";
//See this relatives relations
//Label4.Text += "<a href=\"searchRelatives.aspx\">" + + "</a>";
//Index the counter
cntr += 1;
}
Here is when I tried to use a linkbutton instead:
Code:
while (reader.Read())
{
//Don't print out the hr before the first relative
if(cntr != 1)
Label4.Text += "<hr />";
Label4.Text += "<strong>" + reader["Relation"].ToString() + "</strong>" + ": ";
//See this relatives relations
chsnRltvLnkBttn.Text = reader["RelativeFN"].ToString() + " " + reader["RelativeLN"].ToString() + "<br />";
if (reader["RelativeBP"].ToString() != "")
lbl5.Text += "Birth Place: " + reader["RelativeBP"].ToString();
if (reader["RelativeEmail"].ToString() != "")
lbl5.Text += " | e-Mail: " + reader["RelativeEmail"].ToString();
if (reader["RelativeIM"].ToString() != "")
lbl5.Text += " | Instant Messenger Handle: " + reader["RelativeIM"].ToString() + "<br />";
//See this relatives relations
//Label4.Text += "<a href=\"searchRelatives.aspx\">" + + "</a>";
//Index the counter
cntr += 1;
}
The linkbutton code:
protected void chsnRltvLnkBttn_Click(object sender, EventArgs e)
{
//create session variable to pass along who the relative is
Session["ChosenRelative"] = chsnRltvLnkBttn.Text;
}
-
Jun 24th, 2007, 11:31 AM
#2
Thread Starter
Hyperactive Member
Re: Can I get an idea on how to pass info, trying session but having problems
The way it works now is that when the page loads up, a list of all relatives related to a person logged in are listed. The names of each relative are hyperlinks. When a relatives name is clicked on, it directs them to a new page. What I want to do is create a session variable that holds the name of the relative(the hyperlink) clicked on so that on the next page I can get all that person's relatives from the database to load up on the page. The problem I am having is that I can not distinguish between the relatives in the hyperlink. The way that my code is working actually overwrites the relative session variable in a loop that ends up with every relative having the same name as the last name read from the read loop. I was thinking ok, make a session variable as each link for the relative is created but omg, I am thinking that then I would have a thousand session variables in memory and that that would cause some serious issues on the server if I did it that way. So I am stuck, I don't know how I can make each link distinct enough to create the session variable without making them all sessions.
I hope I cleared this up a little more.
-
Jun 24th, 2007, 10:48 PM
#3
Thread Starter
Hyperactive Member
Re: Can I get an idea on how to pass info, trying session but having problems
I gave it a go and came up with this:
Code:
Label4.Text += "<a href=\"searchrelatives.aspx?Parameter=" + reader["RelativeID"].ToString() +
"\">" + reader["RelativeFN"].ToString() + " " + reader["RelativeLN"].ToString() + "</a>" + "<br />";
and on that next page:
Code:
public partial class searchrelatives : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String ParameterValue = Page.Request.QueryString["Parameter"];
qryStrLbl.Text = ParameterValue;
}
}
But I get this error:
System.IndexOutOfRangeException was unhandled by user code
Message="RelativeID"
at this line:
Code:
Label4.Text += "<a href=\"searchrelatives.aspx?Parameter=" + reader["RelativeID"].ToString() +
"\">" + reader["RelativeFN"].ToString() + " " + reader["RelativeLN"].ToString() + "</a>" + "<br />";
It looks right to me after having tried to correct it a couple of times. I am not sure what could be wrong with it other than I might have messed up my concatenation somehow.
-
Jun 24th, 2007, 11:24 PM
#4
Thread Starter
Hyperactive Member
Re: Can I get an idea on how to pass info, trying session but having problems
WOOHOO, it was just my selection. GOT IT!
YEAH!!!
THANK YOU!!!!!!!!
-
Jun 25th, 2007, 10:07 AM
#5
Re: [RESOLVED] Can I get an idea on how to pass info, trying session but having problems
Talking to yourself again? :P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|