What's wrong with this code?

A

Allixria

Hi all... I need help in there :

In the Page_Load :
///////////////////////////////////////
If Not IsPostBack Then
If Not (Session("CurrentTextBox1") Is Nothing) Then
TextBox1 = Session("CurrentTextBox1") <--- ***
End If
Else
TextBox1.text = "Hello World!"
Session("CurrentTextBox1") = TextBox1
End If
///////////////////////////////////////

Later in some code, there is a Redirect to this page adding a param
value so this page is recalled, and...

*** : TextBox1 is returned as an object, ok, but his .text value is
empty....
What to do with that? Really I think I miss something here!!

TIA,
Ally
 
S

Scott Mitchell [MVP]

Allixria said:
In the Page_Load :
///////////////////////////////////////
If Not IsPostBack Then
If Not (Session("CurrentTextBox1") Is Nothing) Then
TextBox1 = Session("CurrentTextBox1") <--- ***
End If
Else
TextBox1.text = "Hello World!"
Session("CurrentTextBox1") = TextBox1
End If
///////////////////////////////////////

Later in some code, there is a Redirect to this page adding a param
value so this page is recalled, and...

*** : TextBox1 is returned as an object, ok, but his .text value is
empty....
What to do with that? Really I think I miss something here!!

Why are you storing the TextBox object in Session? Why not just the
..Text property value, since that, it appears, is all you care about
persisting?


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
A

Allixria

Hi Scott

In fact, I wanted to simplify the problem.. I used a textbox and it
didn't work, but in fact I want to store a custom treeview object into
a session variable to be able to restore it's design and all of his
nodes..

Here's the code in the page_load :

If Not IsPostBack Then
If Not (Session("CurrentTreeView") Is Nothing) Then
oTree = CType(Session("CurrentTreeView"),
squishyWARE.WebComponents.squishyTREE.TreeView)
Else
PopulateTreeview(oTree)
Session("CurrentTreeView") = oTree
End If
Else
Session("CurrentTreeView") = oTree
End If

TIA
 
A

Allixria

Thanx anyway, I have solved my problem.

I used HttpContext.Current.Cache to cache my treeview object (that I
had to serialize too).

I had to remove and add again the control in the page :

Me.controls.remove(oTree)
Me.controls.add(oTree) because I was having 2 controls...

Below I added:
oTree = ctype(HttpContext.Current.Cache("oTree"),TreeView)
Does anyone knows why I had to remove the oTree control ?
 
A

Alvin Bruney [MVP]

you don't store controls in session, the behavior isn't guaranteed. In fact,
nested hierarchies of objects in the tree won't function correctly after
retrieving from session. that has been my experience.
 
A

Allixria

Thanx for the warning Alvin, and sorry everybody for the
"clearness-less" of my previous explanations! Maybe I was too tired,
bugging at this problem.

I often forget too that all of you have no idea of where I'm in, and I
forget to be more clear when explaining my problem...

For this tree control, I have to tell that even if this custom control
was great, it have some problems... I choose it because there was easy
access to storing keys, and to find them, unlike the MS one in the
WebControls package. I wanted too to be able to customize this treeview
(css styles for example). So I used this little "unsupported now"
control but it seems to do the job for now.

This control has only the job to send the node's key in querystring
when it is clicked, and then another control in the page has the job to
see if this querystring is empty or not to display properly his stuff.
The treeview has no behaviours more to do, than only one in fact (and
that was my problem ) : to keep your nodes opened and closed as you
were the last time the person clicked on it.

What I try to do : A Knowledge base articles ...

Thanx for your help!
p.s. This treeview was free and available at gotdotnet if anyone
wonders... made in C# by asills.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top