What's wrong with this code?

Discussion in 'ASP .Net Web Controls' started by Allixria, Oct 18, 2004.

  1. Allixria

    Allixria Guest

    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
     
    Allixria, Oct 18, 2004
    #1
    1. Advertising

  2. Allixria wrote:
    > 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

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Oct 18, 2004
    #2
    1. Advertising

  3. Allixria

    Allixria Guest

    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
     
    Allixria, Oct 18, 2004
    #3
  4. Allixria

    Allixria Guest

    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 ?
     
    Allixria, Oct 19, 2004
    #4
  5. 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.

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Allixria" <> wrote in message
    news:...
    > 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 ?
    >
     
    Alvin Bruney [MVP], Oct 19, 2004
    #5
  6. Allixria

    Allixria Guest

    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.
     
    Allixria, Oct 19, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    2,218
    Ralf Hildebrandt
    Sep 10, 2003
  2. willem oosthuizen

    What is wrong with the following code?

    willem oosthuizen, Oct 10, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,308
  3. Matthew
    Replies:
    7
    Views:
    742
    Priscilla Walmsley
    Jan 7, 2005
  4. David. E. Goble
    Replies:
    9
    Views:
    492
    David. E. Goble
    Feb 2, 2005
  5. kiran
    Replies:
    12
    Views:
    1,154
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page