Retrieving contained Controls during postback using LoadPostData

Discussion in 'ASP .Net' started by Nathan Sokalski, Sep 27, 2007.

  1. I am writing a Control that inherits from
    System.Web.UI.WebControls.CompositeControl. Like many Controls, my Control
    renders more than just one inner Control. When a postback occurs, I need to
    get the data posted by these inner Controls (by using the postCollection
    argument). However, the postDataKey argument gives the key for the id of the
    outer Control. When I need to access the value posted by one of the inner
    Controls, I have found that I need to enter the id as a literal String for
    the key, but this seems a little too simple for me, with all the Controls
    that could get created. Is there some property or method that I should be
    using to determine the key? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Sep 27, 2007
    #1
    1. Advertising

  2. Nathan Sokalski

    Teemu Keiski Guest

    Hi,

    Control's UniqueID property is usually used as key in form post collection.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Nathan Sokalski" <> wrote in message
    news:...
    >I am writing a Control that inherits from
    >System.Web.UI.WebControls.CompositeControl. Like many Controls, my Control
    >renders more than just one inner Control. When a postback occurs, I need to
    >get the data posted by these inner Controls (by using the postCollection
    >argument). However, the postDataKey argument gives the key for the id of
    >the outer Control. When I need to access the value posted by one of the
    >inner Controls, I have found that I need to enter the id as a literal
    >String for the key, but this seems a little too simple for me, with all the
    >Controls that could get created. Is there some property or method that I
    >should be using to determine the key? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Teemu Keiski, Sep 27, 2007
    #2
    1. Advertising

  3. That's what I thought, and what I have used in a previous Control of mine,
    but when I try to do that here I am recieving an error that the Control does
    not exist. When I did a debug session I found that the value of the Control
    was Nothing. Therefore, I cannot get to the UniqueID. Any idea what could be
    causing this? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    "Teemu Keiski" <> wrote in message
    news:uedY%...
    > Hi,
    >
    > Control's UniqueID property is usually used as key in form post
    > collection.
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >>I am writing a Control that inherits from
    >>System.Web.UI.WebControls.CompositeControl. Like many Controls, my Control
    >>renders more than just one inner Control. When a postback occurs, I need
    >>to get the data posted by these inner Controls (by using the
    >>postCollection argument). However, the postDataKey argument gives the key
    >>for the id of the outer Control. When I need to access the value posted by
    >>one of the inner Controls, I have found that I need to enter the id as a
    >>literal String for the key, but this seems a little too simple for me,
    >>with all the Controls that could get created. Is there some property or
    >>method that I should be using to determine the key? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
    >
     
    Nathan Sokalski, Sep 27, 2007
    #3
  4. Nathan Sokalski

    Teemu Keiski Guest

    Does your control create child controls in CreateChildControls?. That way
    you ensure controls are there when you access the Controls collection.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Nathan Sokalski" <> wrote in message
    news:...
    > That's what I thought, and what I have used in a previous Control of mine,
    > but when I try to do that here I am recieving an error that the Control
    > does not exist. When I did a debug session I found that the value of the
    > Control was Nothing. Therefore, I cannot get to the UniqueID. Any idea
    > what could be causing this? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    > "Teemu Keiski" <> wrote in message
    > news:uedY%...
    >> Hi,
    >>
    >> Control's UniqueID property is usually used as key in form post
    >> collection.
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >> "Nathan Sokalski" <> wrote in message
    >> news:...
    >>>I am writing a Control that inherits from
    >>>System.Web.UI.WebControls.CompositeControl. Like many Controls, my
    >>>Control renders more than just one inner Control. When a postback occurs,
    >>>I need to get the data posted by these inner Controls (by using the
    >>>postCollection argument). However, the postDataKey argument gives the key
    >>>for the id of the outer Control. When I need to access the value posted
    >>>by one of the inner Controls, I have found that I need to enter the id as
    >>>a literal String for the key, but this seems a little too simple for me,
    >>>with all the Controls that could get created. Is there some property or
    >>>method that I should be using to determine the key? Thanks.
    >>> --
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 27, 2007
    #4
  5. Nathan Sokalski

    Teemu Keiski Guest

    Note: if you access Control instance directly, call EnsureChildControls
    before that


    "Teemu Keiski" <> wrote in message
    news:%...
    > Does your control create child controls in CreateChildControls?. That way
    > you ensure controls are there when you access the Controls collection.
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >> That's what I thought, and what I have used in a previous Control of
    >> mine, but when I try to do that here I am recieving an error that the
    >> Control does not exist. When I did a debug session I found that the value
    >> of the Control was Nothing. Therefore, I cannot get to the UniqueID. Any
    >> idea what could be causing this? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >> "Teemu Keiski" <> wrote in message
    >> news:uedY%...
    >>> Hi,
    >>>
    >>> Control's UniqueID property is usually used as key in form post
    >>> collection.
    >>>
    >>> --
    >>> Teemu Keiski
    >>> AspInsider, ASP.NET MVP
    >>> http://blogs.aspadvice.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>>
    >>> "Nathan Sokalski" <> wrote in message
    >>> news:...
    >>>>I am writing a Control that inherits from
    >>>>System.Web.UI.WebControls.CompositeControl. Like many Controls, my
    >>>>Control renders more than just one inner Control. When a postback
    >>>>occurs, I need to get the data posted by these inner Controls (by using
    >>>>the postCollection argument). However, the postDataKey argument gives
    >>>>the key for the id of the outer Control. When I need to access the value
    >>>>posted by one of the inner Controls, I have found that I need to enter
    >>>>the id as a literal String for the key, but this seems a little too
    >>>>simple for me, with all the Controls that could get created. Is there
    >>>>some property or method that I should be using to determine the key?
    >>>>Thanks.
    >>>> --
    >>>> Nathan Sokalski
    >>>>
    >>>> http://www.nathansokalski.com/
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 27, 2007
    #5
  6. Thank you for your help, I should probably be slapping myself in the head
    for my mistake: I created the Controls in CreateChildControls, but forgot
    the Me.Controls.Add() method! Thanks again for your help.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Teemu Keiski" <> wrote in message
    news:%...
    > Does your control create child controls in CreateChildControls?. That way
    > you ensure controls are there when you access the Controls collection.
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >> That's what I thought, and what I have used in a previous Control of
    >> mine, but when I try to do that here I am recieving an error that the
    >> Control does not exist. When I did a debug session I found that the value
    >> of the Control was Nothing. Therefore, I cannot get to the UniqueID. Any
    >> idea what could be causing this? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >> "Teemu Keiski" <> wrote in message
    >> news:uedY%...
    >>> Hi,
    >>>
    >>> Control's UniqueID property is usually used as key in form post
    >>> collection.
    >>>
    >>> --
    >>> Teemu Keiski
    >>> AspInsider, ASP.NET MVP
    >>> http://blogs.aspadvice.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>>
    >>> "Nathan Sokalski" <> wrote in message
    >>> news:...
    >>>>I am writing a Control that inherits from
    >>>>System.Web.UI.WebControls.CompositeControl. Like many Controls, my
    >>>>Control renders more than just one inner Control. When a postback
    >>>>occurs, I need to get the data posted by these inner Controls (by using
    >>>>the postCollection argument). However, the postDataKey argument gives
    >>>>the key for the id of the outer Control. When I need to access the value
    >>>>posted by one of the inner Controls, I have found that I need to enter
    >>>>the id as a literal String for the key, but this seems a little too
    >>>>simple for me, with all the Controls that could get created. Is there
    >>>>some property or method that I should be using to determine the key?
    >>>>Thanks.
    >>>> --
    >>>> Nathan Sokalski
    >>>>
    >>>> http://www.nathansokalski.com/
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Nathan Sokalski, Sep 27, 2007
    #6
    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. Sam
    Replies:
    2
    Views:
    4,489
  2. Nathan Sokalski
    Replies:
    4
    Views:
    421
    Nathan Sokalski
    Jul 21, 2006
  3. Nathan Sokalski

    System.OverflowException during IPostBackDataHandler.LoadPostData

    Nathan Sokalski, Jul 20, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    189
    Nathan Sokalski
    Jul 21, 2006
  4. Nathan Sokalski

    Retrieving contained Controls during postback using LoadPostData

    Nathan Sokalski, Sep 27, 2007, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    771
    Nathan Sokalski
    Sep 27, 2007
  5. Warped
    Replies:
    2
    Views:
    513
    Warped
    Jul 15, 2005
Loading...

Share This Page