Problem with asp:UpdatePanel inside a Web User Control

Discussion in 'ASP .Net' started by musosdev, Sep 28, 2009.

  1. musosdev

    musosdev Guest

    Hi guys

    I've created a nice little Comments UI engine. Comments can be added, and
    are automatically added to the list of comments below, in a nice AJAX way,
    using Update Panels and the like.

    I'm trying to encapsulate this functionality in a web user control. I've got
    the control working, sort of, but the variables I need (the item we're
    commenting on, etc), get deleted on the AJAX postback. Can anyone shed some
    light on how to fix this...?

    Here's the lines from the aspx...

    <%@ Register src="../../_ctrl/Comments.ascx" tagname="Comments"
    tagprefix="uc1" %>
    ....
    <uc1:Comments ID="comComments" runat="server" />

    And the C# that passes the variables...

    // comments
    comComments.ItemType = CommentTypes.Project;
    comComments.ItemID = pid;

    These variables are declared as public string. I tried static, but then I
    need to use an instance of my WebUserControl class. I'm not sure that's right?

    Anyway, the first time the page runs, the ItemType and ItemID are passed
    fine, and then a partial postback (of the UpdatePanel) occurs, both of these
    items are null.

    How can I persist them through the postback?

    Thanks



    Dan
    musosdev, Sep 28, 2009
    #1
    1. Advertising

  2. musosdev

    musosdev Guest

    Hi again

    Just wanted to say I've sorted it. I created some public variables with
    get/set..

    public string var { get {} set {} }

    and then create private variables which were able to be static.

    Of course, if anyone knows of a better way, I'd love to hear!

    Cheers


    Dan

    "musosdev" wrote:

    > Hi guys
    >
    > I've created a nice little Comments UI engine. Comments can be added, and
    > are automatically added to the list of comments below, in a nice AJAX way,
    > using Update Panels and the like.
    >
    > I'm trying to encapsulate this functionality in a web user control. I've got
    > the control working, sort of, but the variables I need (the item we're
    > commenting on, etc), get deleted on the AJAX postback. Can anyone shed some
    > light on how to fix this...?
    >
    > Here's the lines from the aspx...
    >
    > <%@ Register src="../../_ctrl/Comments.ascx" tagname="Comments"
    > tagprefix="uc1" %>
    > ...
    > <uc1:Comments ID="comComments" runat="server" />
    >
    > And the C# that passes the variables...
    >
    > // comments
    > comComments.ItemType = CommentTypes.Project;
    > comComments.ItemID = pid;
    >
    > These variables are declared as public string. I tried static, but then I
    > need to use an instance of my WebUserControl class. I'm not sure that's right?
    >
    > Anyway, the first time the page runs, the ItemType and ItemID are passed
    > fine, and then a partial postback (of the UpdatePanel) occurs, both of these
    > items are null.
    >
    > How can I persist them through the postback?
    >
    > Thanks
    >
    >
    >
    > Dan
    musosdev, Sep 28, 2009
    #2
    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. Replies:
    3
    Views:
    471
    Rob Meade
    Aug 8, 2007
  2. Leon Mayne
    Replies:
    5
    Views:
    4,738
    Leon Mayne
    May 27, 2008
  3. Frank
    Replies:
    2
    Views:
    3,960
    Frank
    Jan 10, 2009
  4. Nathan Sokalski
    Replies:
    1
    Views:
    570
    miher
    Jun 15, 2009
  5. Kiran More
    Replies:
    2
    Views:
    304
    Kiran More
    Nov 14, 2006
Loading...

Share This Page