Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Losing user control

    Hi all,

    I am setting up a tab strip in an aspx page. I am using
    link buttons to switch between the tabs (at the moment,
    it is just link buttons, no tabs...)

    Under each link button, I intend to add a usercontrol. I
    have written one so far. I am adding the UC dynamically
    in the button click event of my tab strip.

    I am also setting properties and calling a method in the
    UC.

    My UC is set up like a wizard using back and next buttons
    to go backwards and forwards.

    However, on the first page of the UC, if I click next, I
    lose the control altogethor.

    I am assuming that I probably need to hold the UC in the
    viewstate somehow, but I don't know how to do that.

    Also, if I switch tabs and load a different UC, will I
    lose what has been entered in the UC that is no longer
    being viewed?

    Here is my code...
    The ApplicationOverviewLinkButton is the one that will be
    one of my tab buttons.


    private void
    ApplicationOverviewLinkButton_Click(object sender,
    System.EventArgs e)
    {
    UserControl MyRegistration =
    (UserControl)LoadControl
    ("../CMSUserControls/nqt/registration.ascx");

    RegistrationDetailPanel.Controls.Add
    (MyRegistration);


    ((MyCMSApp.CMSUserControls.nqt.registration)
    MyRegistration).LoggedInUser = "LoggedInUserName";

    ((MyCMSApp.CMSUserControls.nqt.registration)
    MyRegistration).FillData();
    RegistrationDetailPanel.Visible =
    true;
    MyRegistration.Visible = true;
    }


    Thanks for any help.

    Regards,
    Dave Colliver.
    [url]http://www.IlfracombeFOCUS.com[/url]
    ~~
    [url]http://www,FOCUSPortals.com[/url] - Portal franchises available

    David Colliver Guest

  2. Similar Questions and Discussions

    1. user control problem access value from user control to a page
      Thanks a lot for paying attention to my problem , i tell u the problem i have a main form in which i gave a login label that points to a...
    2. Losing Composite Control property that another Composite Control ...
      Hi, I'm creating 2 composite controls in ASP.net. Control 1 is a Search control and control 2 is a Map control. I have added a property...
    3. Dynamically Adding User Control with Child User Control
      I have a user control that has a child user control. If I drag this onto the page, it appears and functions normally. If I attempt to add the...
    4. Know in user control page_load if an user control event is going to be fired
      Hi all, i have built a user control that shows a map and let the user zoom in, out, usual stuff. Putting this object in a webform the user can...
    5. Losing viewstate in custom control
      I have a custom control I derived from the datagrid control and set a couple of values in viewstate("foo") = "bar" but on postback they are...
  3. #2

    Default Re: Losing user control

    Any controls you dynamically add to the page need to be recreated upon postback.
    Here's a sample that shows how to "remember' across postbacks what controls
    were added:

    [url]http://groups-beta.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/5e4ba4cfe5902a4b/a5717a97bd32c450?q=brock+dynamic+controls+viewstat e&rnum=1[/url]

    -Brock
    DevelopMentor
    [url]http://staff.develop.com/ballen[/url]


    > Hi all,
    >
    > I am setting up a tab strip in an aspx page. I am using link buttons
    > to switch between the tabs (at the moment, it is just link buttons, no
    > tabs...)
    >
    > Under each link button, I intend to add a usercontrol. I have written
    > one so far. I am adding the UC dynamically in the button click event
    > of my tab strip.
    >
    > I am also setting properties and calling a method in the UC.
    >
    > My UC is set up like a wizard using back and next buttons to go
    > backwards and forwards.
    >
    > However, on the first page of the UC, if I click next, I lose the
    > control altogethor.
    >
    > I am assuming that I probably need to hold the UC in the viewstate
    > somehow, but I don't know how to do that.
    >
    > Also, if I switch tabs and load a different UC, will I lose what has
    > been entered in the UC that is no longer being viewed?
    >
    > Here is my code...
    > The ApplicationOverviewLinkButton is the one that will be
    > one of my tab buttons.
    > private void
    > ApplicationOverviewLinkButton_Click(object sender,
    > System.EventArgs e)
    > {
    > UserControl MyRegistration =
    > (UserControl)LoadControl
    > ("../CMSUserControls/nqt/registration.ascx");
    >
    > RegistrationDetailPanel.Controls.Add
    > (MyRegistration);
    > ((MyCMSApp.CMSUserControls.nqt.registration)
    > MyRegistration).LoggedInUser = "LoggedInUserName";
    > ((MyCMSApp.CMSUserControls.nqt.registration)
    > MyRegistration).FillData();
    > RegistrationDetailPanel.Visible =
    > true;
    > MyRegistration.Visible = true;
    > }
    > Thanks for any help.
    >
    > Regards,
    > Dave Colliver.
    > [url]http://www.IlfracombeFOCUS.com[/url]
    > ~~
    > [url]http://www,FOCUSPortals.com[/url] - Portal franchises available


    Brock Allen Guest

  4. #3

    Default Re: Losing user control

    Hi Brock,

    Magic. :-)

    I am assuming though that as the control is not held
    during postback (or is it?) that I need to save the
    content (forms on each page) at every single postback.

    I noted you answered my question on the security group. I
    need to supply more info as I don't think your current
    reply really fits.

    Best regards,
    Dave Colliver.
    [url]http://www.CardiffFOCUS.com[/url]

    >-----Original Message-----
    >Any controls you dynamically add to the page need to be
    recreated upon postback.
    >Here's a sample that shows how to "remember' across
    postbacks what controls
    >were added:
    >
    >[url]http://groups-[/url]
    beta.google.com/group/microsoft.public.dotnet.framework.as
    pnet/browse_thread/thread/5e4ba4cfe5902a4b/a5717a97bd32c45
    0?q=brock+dynamic+controls+viewstate&rnum=1
    >
    >-Brock
    >DevelopMentor
    >[url]http://staff.develop.com/ballen[/url]
    >
    >
    >
    >> Hi all,
    >>
    >> I am setting up a tab strip in an aspx page. I am
    using link buttons
    >> to switch between the tabs (at the moment, it is just
    link buttons, no
    >> tabs...)
    >>
    >> Under each link button, I intend to add a usercontrol.
    I have written
    >> one so far. I am adding the UC dynamically in the
    button click event
    >> of my tab strip.
    >>
    >> I am also setting properties and calling a method in
    the UC.
    >>
    >> My UC is set up like a wizard using back and next
    buttons to go
    >> backwards and forwards.
    >>
    >> However, on the first page of the UC, if I click next,
    I lose the
    >> control altogethor.
    >>
    >> I am assuming that I probably need to hold the UC in
    the viewstate
    >> somehow, but I don't know how to do that.
    >>
    >> Also, if I switch tabs and load a different UC, will I
    lose what has
    >> been entered in the UC that is no longer being viewed?
    >>
    >> Here is my code...
    >> The ApplicationOverviewLinkButton is the one that will
    be
    >> one of my tab buttons.
    >> private void
    >> ApplicationOverviewLinkButton_Click(object sender,
    >> System.EventArgs e)
    >> {
    >> UserControl MyRegistration =
    >> (UserControl)LoadControl
    >> ("../CMSUserControls/nqt/registration.ascx");
    >>
    >> RegistrationDetailPanel.Controls.Add
    >> (MyRegistration);
    >> ((MyCMSApp.CMSUserControls.nqt.registration)
    >> MyRegistration).LoggedInUser = "LoggedInUserName";
    >> ((MyCMSApp.CMSUserControls.nqt.registration)
    >> MyRegistration).FillData();
    >> RegistrationDetailPanel.Visible =
    >> true;
    >> MyRegistration.Visible = true;
    >> }
    >> Thanks for any help.
    >>
    >> Regards,
    >> Dave Colliver.
    >> [url]http://www.IlfracombeFOCUS.com[/url]
    >> ~~
    >> [url]http://www,FOCUSPortals.com[/url] - Portal franchises
    available
    >
    >
    >
    >.
    >
    David Colliver Guest

  5. #4

    Default Re: Losing user control

    Hi Brock,

    I just discovered a slight flaw...

    Say I have 3 tabs. The first tab has a usercontrol that
    in itself has more than 1 page. The second and third tab
    have a simple single page usercontrol.

    Now, if I go to the first tab, I can next and previous
    the pages in the first user control OK.

    If I switch to the second (or 3rd) tab, these switch OK.

    If I now go back to the first one, this swiches OK, but
    if I next the page on the first tab, then I get the
    content of the 2nd/3rd tab also displayed.

    This is incremental. If I switch to the 2nd tab, then
    back to first, then page in the first, the 2nd tabs
    usercontrol is added to the list, so for each tab switch,
    I get more and more content on the page.

    I think I need to somehow drop the items in the
    DynamicContent arraylist, but now sure where I should do
    this.

    Cheers.
    Dave Colliver.
    [url]http://www.GreatYarmouthFOCUS.com[/url]

    >-----Original Message-----
    >Hi Brock,
    >
    >Magic. :-)
    >
    >I am assuming though that as the control is not held
    >during postback (or is it?) that I need to save the
    >content (forms on each page) at every single postback.
    >
    >I noted you answered my question on the security group.
    I
    >need to supply more info as I don't think your current
    >reply really fits.
    >
    >Best regards,
    >Dave Colliver.
    >[url]http://www.CardiffFOCUS.com[/url]
    >
    >
    >>-----Original Message-----
    >>Any controls you dynamically add to the page need to be
    >recreated upon postback.
    >>Here's a sample that shows how to "remember' across
    >postbacks what controls
    >>were added:
    >>
    >>[url]http://groups-[/url]
    >beta.google.com/group/microsoft.public.dotnet.framework.a
    s
    >pnet/browse_thread/thread/5e4ba4cfe5902a4b/a5717a97bd32c4
    5
    >0?q=brock+dynamic+controls+viewstate&rnum=1
    >>
    >>-Brock
    >>DevelopMentor
    >>[url]http://staff.develop.com/ballen[/url]
    >>
    >>
    >>
    >>> Hi all,
    >>>
    >>> I am setting up a tab strip in an aspx page. I am
    >using link buttons
    >>> to switch between the tabs (at the moment, it is just
    >link buttons, no
    >>> tabs...)
    >>>
    >>> Under each link button, I intend to add a
    usercontrol.
    >I have written
    >>> one so far. I am adding the UC dynamically in the
    >button click event
    >>> of my tab strip.
    >>>
    >>> I am also setting properties and calling a method in
    >the UC.
    >>>
    >>> My UC is set up like a wizard using back and next
    >buttons to go
    >>> backwards and forwards.
    >>>
    >>> However, on the first page of the UC, if I click
    next,
    >I lose the
    >>> control altogethor.
    >>>
    >>> I am assuming that I probably need to hold the UC in
    >the viewstate
    >>> somehow, but I don't know how to do that.
    >>>
    >>> Also, if I switch tabs and load a different UC, will
    I
    >lose what has
    >>> been entered in the UC that is no longer being viewed?
    >>>
    >>> Here is my code...
    >>> The ApplicationOverviewLinkButton is the one that
    will
    >be
    >>> one of my tab buttons.
    >>> private void
    >>> ApplicationOverviewLinkButton_Click(object sender,
    >>> System.EventArgs e)
    >>> {
    >>> UserControl MyRegistration =
    >>> (UserControl)LoadControl
    >>> ("../CMSUserControls/nqt/registration.ascx");
    >>>
    >>> RegistrationDetailPanel.Controls.Add
    >>> (MyRegistration);
    >>> ((MyCMSApp.CMSUserControls.nqt.registration)
    >>> MyRegistration).LoggedInUser = "LoggedInUserName";
    >>> ((MyCMSApp.CMSUserControls.nqt.registration)
    >>> MyRegistration).FillData();
    >>> RegistrationDetailPanel.Visible =
    >>> true;
    >>> MyRegistration.Visible = true;
    >>> }
    >>> Thanks for any help.
    >>>
    >>> Regards,
    >>> Dave Colliver.
    >>> [url]http://www.IlfracombeFOCUS.com[/url]
    >>> ~~
    >>> [url]http://www,FOCUSPortals.com[/url] - Portal franchises
    >available
    >>
    >>
    >>
    >>.
    >>
    >.
    >
    David Colliver Guest

  6. #5

    Default Re: Losing user control

    > I am assuming though that as the control is not held during postback
    > (or is it?) that I need to save the content (forms on each page) at
    > every single postback.
    As long as you recreate the controls like I showed in the sample from the
    link, they do hold their own state. You should not have to manually reset
    their state. That would defeat the whole purpose of using server controls.

    -Brock
    DevelopMentor
    [url]http://staff.develop.com/ballen[/url]



    Brock Allen Guest

  7. #6

    Default Re: Losing user control

    > If I now go back to the first one, this swiches OK, but if I next the
    > page on the first tab, then I get the content of the 2nd/3rd tab also
    > displayed.
    This sounds like a flaw in how the tab controls tracks which tab it should
    be on.

    -Brock
    DevelopMentor
    [url]http://staff.develop.com/ballen[/url]




    Brock Allen Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139