Results 1 to 4 of 4

Thread: Page Load [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Resolved Page Load [RESOLVED]

    I'm not sure if this is a question even worth asking here, but coming from Window's Forms apps, to Web applications is a bit strange....

    I got a LoadBorderStyles method, that loop through all the members in the BorderStyle (TreeView) enumeration, convert each member to string and pop it into a listbox. Obviously I only want this method to run once.

    Then I got a Treeview, and apply the borderstyle the user click in the listbox to the treeview (covert the sting back to enumeration member).

    This all work fine, but each time I click a borderstyle, it is applied correctly, but the the LoadBorderStyles method, which I call from the Page_Load is excecuted again.

    When I add the following line to the LoadBorderStyles method : lstBorderStyles.Items.Clear(); i get a "Object reference not set to an instance of an object" error

    Here is my code

    Code:
    public partial class TestWhosTreeView17 : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        myTreeView.TreeNodeSrc = "xml/treenode.xml";
        myTreeView.DataBind();
    
        myTreeView.Height = lstBorderStyles.Height;
        myTreeView.Width = lstBorderStyles.Width;
    
        LoadBorderStyles();
    
      }
    
      private void LoadBorderStyles()
      {
    
        lstBorderStyles.Items.Clear();
        //loop through all the borderstyle enumeration members, convert to
        //string and add to listbox
          foreach (string s in Enum.GetNames(typeof(System.Web.UI.WebControls.BorderStyle)))
          {
            lstBorderStyles.Items.Add(s);
        }
      }
    
      protected void lstBorderStyles_SelectedIndexChanged(object sender, EventArgs e)
      {
          //convert the selected item's text to a borderstyle enumeration member
          //apply the borderstyle member to the treeview's borderstyle property
          myTreeView.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), lstBorderStyles.SelectedItem.Text);
        
      }
    }
    Last edited by StrangerInBeijing; May 19th, 2005 at 01:40 AM. Reason: RESOLVED

  2. #2
    Member
    Join Date
    Mar 2005
    Posts
    43

    Re: Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
    myTreeView.TreeNodeSrc = "xml/treenode.xml";
    myTreeView.DataBind();

    myTreeView.Height = lstBorderStyles.Height;
    myTreeView.Width = lstBorderStyles.Width;
    if(!this.Page.IsPostBack)
    LoadBorderStyles();

    }


    now the method LoadBorderStyle will only be run once, and that is when the page is loaded, not if it is just post back ;-)

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Page Load

    aaaaah....I've seen that word in other pages, but never thougth about it twice...

    Cool, will do that and also read up on what it does!

    Thanx hey!

  4. #4
    Member
    Join Date
    Mar 2005
    Posts
    43

    Re: Page Load

    no problem ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width