Determining selected node in OnInit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWlrZSBDb2xsaW5z?=

    Determining selected node in OnInit

    In my web application, I have a treeview. Based on which node is clicked, I
    am loading user controls. Currently, I am loading my controls in the
    SelectedNodeCha nged event, but I want to load the user controls in OnInit so
    I can have them in the ViewState, but the treeview is not created yet. Is
    this possible, or do I need to keep loading my user controls after the OnInit
    event?

    Example of what I am doing now:
    protected void tvAccountSetup_ SelectedNodeCha nged(object sender, EventArgs e)
    {
    AddControl(@"Us erControls\" + tvAccountSetup. ID.Substring(2) + @"\" +
    tvAccountSetup. SelectedValue + ".ascx");
    }

    private void AddControl(stri ng control)
    {
    //In case the page cannot be found, with this code in a try catch, it will
    not error.
    try
    {
    PlaceHolder1.Co ntrols.Clear();
    Control c = Page.LoadContro l(control);
    PlaceHolder1.Co ntrols.Add(c);
    }
    catch
    {
    }

  • Gaurav Vaish \(a.k.a. MasterGaurav\)

    #2
    Re: Determining selected node in OnInit

    am loading user controls. Currently, I am loading my controls in the
    SelectedNodeCha nged event, but I want to load the user controls in OnInit
    so
    I can have them in the ViewState, but the treeview is not created yet. Is
    Why would you need that?
    The events have been structured in such a manner that you don't need to do
    all that juggling.

    Is there any specific reason as to why you need to "load" the controls
    during "OnInit"?
    btw, you don't need to "load" them in OnInit to participate in ViewState.

    They must be added in the method AddChildControl s().


    HTH.


    --
    Happy Hacking,
    Gaurav Vaish | http://dwt.sourceforge.net
    http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
    --------------------------------




    Comment

    • Eliyahu Goldin

      #3
      Re: Determining selected node in OnInit

      Request.Form collection is available in OnInit event. Set a breakpoint on
      the event, look into the Request.Form and see if it contains any info that
      you can use.

      --
      Eliyahu Goldin,
      Software Developer
      Microsoft MVP [ASP.NET]




      "Mike Collins" <MikeCollins@di scussions.micro soft.comwrote in message
      news:358E9A68-FE05-4830-9310-7C44EBC488E9@mi crosoft.com...
      In my web application, I have a treeview. Based on which node is clicked,
      I
      am loading user controls. Currently, I am loading my controls in the
      SelectedNodeCha nged event, but I want to load the user controls in OnInit
      so
      I can have them in the ViewState, but the treeview is not created yet. Is
      this possible, or do I need to keep loading my user controls after the
      OnInit
      event?
      >
      Example of what I am doing now:
      protected void tvAccountSetup_ SelectedNodeCha nged(object sender, EventArgs
      e)
      {
      AddControl(@"Us erControls\" + tvAccountSetup. ID.Substring(2) + @"\" +
      tvAccountSetup. SelectedValue + ".ascx");
      }
      >
      private void AddControl(stri ng control)
      {
      //In case the page cannot be found, with this code in a try catch, it will
      not error.
      try
      {
      PlaceHolder1.Co ntrols.Clear();
      Control c = Page.LoadContro l(control);
      PlaceHolder1.Co ntrols.Add(c);
      }
      catch
      {
      }
      >

      Comment

      • =?Utf-8?B?TWlrZSBDb2xsaW5z?=

        #4
        Re: Determining selected node in OnInit

        Why would you need that?

        I thought that when you dynamically load controls, you were supposed to do
        that in OnInit so the control would be part of the pages ViewState. This way
        if the page gets refreshed, the control will not disappear. I will look into
        the AddChildControl s method. Thanks.

        "Gaurav Vaish (a.k.a. MasterGaurav)" wrote:
        am loading user controls. Currently, I am loading my controls in the
        SelectedNodeCha nged event, but I want to load the user controls in OnInit
        so
        I can have them in the ViewState, but the treeview is not created yet. Is
        >
        Why would you need that?
        The events have been structured in such a manner that you don't need to do
        all that juggling.
        >
        Is there any specific reason as to why you need to "load" the controls
        during "OnInit"?
        btw, you don't need to "load" them in OnInit to participate in ViewState.
        >
        They must be added in the method AddChildControl s().
        >
        >
        HTH.
        >
        >
        --
        Happy Hacking,
        Gaurav Vaish | http://dwt.sourceforge.net
        http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
        --------------------------------
        >
        >
        >
        >
        >

        Comment

        • =?Utf-8?B?TWlrZSBDb2xsaW5z?=

          #5
          Re: Determining selected node in OnInit

          Thanks...I'll look into that.

          "Eliyahu Goldin" wrote:
          Request.Form collection is available in OnInit event. Set a breakpoint on
          the event, look into the Request.Form and see if it contains any info that
          you can use.
          >
          --
          Eliyahu Goldin,
          Software Developer
          Microsoft MVP [ASP.NET]


          >
          >
          "Mike Collins" <MikeCollins@di scussions.micro soft.comwrote in message
          news:358E9A68-FE05-4830-9310-7C44EBC488E9@mi crosoft.com...
          In my web application, I have a treeview. Based on which node is clicked,
          I
          am loading user controls. Currently, I am loading my controls in the
          SelectedNodeCha nged event, but I want to load the user controls in OnInit
          so
          I can have them in the ViewState, but the treeview is not created yet. Is
          this possible, or do I need to keep loading my user controls after the
          OnInit
          event?

          Example of what I am doing now:
          protected void tvAccountSetup_ SelectedNodeCha nged(object sender, EventArgs
          e)
          {
          AddControl(@"Us erControls\" + tvAccountSetup. ID.Substring(2) + @"\" +
          tvAccountSetup. SelectedValue + ".ascx");
          }

          private void AddControl(stri ng control)
          {
          //In case the page cannot be found, with this code in a try catch, it will
          not error.
          try
          {
          PlaceHolder1.Co ntrols.Clear();
          Control c = Page.LoadContro l(control);
          PlaceHolder1.Co ntrols.Add(c);
          }
          catch
          {
          }
          >
          >
          >

          Comment

          Working...