LoadControl and the PostBack problem

Discussion in 'ASP .Net' started by jack, Jul 28, 2008.

  1. jack

    jack Guest

    Hi folks,
    Consider a page consisting of a treeview, and a panel. The panel is
    supposed to be refreshed based on treeview node selection.

    protected void tree_SelectedNodeChanged(object sender, EventArgs e)
    {
    TreeNode node = this.tree.SelectedNode;
    if (node != null)
    LoadMyControls(node);
    }

    Where LoadMyControls simply loads the associated control based on the
    node and adds it to the panel's controls collection. The loaded
    control, on the other side, is supposed to have a DropDownList
    control, which based on user selection updates a gridview. However,
    when a new item is selected in the combo box, the entire panel is
    vanished and a blank page appears.

    AFAIK, This indicates that the control has to be loaded again, hence,
    the LoadMyControls has to be invoked. So I added the following lines
    to the Page_Load function:

    Boolean isTreeThePostBackSource =
    this.scriptManager.AsyncPostBackSourceElementID.Equals(this.tree.UniqueID);
    if (!isTreeThePostBackSource)
    {
    TreeNode node = this.tree.SelectedNode;
    if (node != null)
    LoadMyControls(node);
    }

    This way, everything works fine.

    However, I've noticed that IsPostBack is always true, when the User
    Control gets loaded. So, I've got no mechanism to learn whether the
    user control should be initialized for the first time. How am I
    supposed to do this?

    Any help would be highly appreciated,

    Thanks
    Jack
    jack, Jul 28, 2008
    #1
    1. Advertising

  2. jack

    Munna Guest

    Hi,

    "However, I've noticed that IsPostBack is always true,"

    Page.IsPostback Is false when the page is requested for the first
    time...
    after each subsequent submit from any control the value is this
    variable is false

    regards

    Munna
    Munna, Jul 28, 2008
    #2
    1. Advertising

  3. jack

    jack Guest

    On Jul 28, 10:24 pm, Munna <> wrote:
    > Hi,
    >
    > "However, I've noticed that IsPostBack is always true,"
    >
    > Page.IsPostback Is false when the page is requested for the first
    > time...
    > after each subsequent submit from any control the value is this
    > variable is false
    >
    > regards
    >
    > Munna


    That's not the case when you use the LoadControl to load a user
    control dynamically!
    jack, Jul 29, 2008
    #3
    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. Craig Buchanan

    LoadControl and PostBack

    Craig Buchanan, Feb 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,898
    Kevin Spencer
    Feb 12, 2004
  2. Craig Buchanan

    LoadControl and PostBack

    Craig Buchanan, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    296
    Craig Buchanan
    Feb 20, 2004
  3. Craig Buchanan

    LoadControl and PostBack Issue

    Craig Buchanan, Feb 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,163
    Craig Buchanan
    Feb 20, 2004
  4. =?Utf-8?B?UmV4VmFu?=

    LoadControl() problem

    =?Utf-8?B?UmV4VmFu?=, Aug 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,253
    Stefan
    Aug 31, 2004
  5. Deane
    Replies:
    0
    Views:
    846
    Deane
    Sep 3, 2007
Loading...

Share This Page