ViewState Problem with Composite Control

Discussion in 'ASP .Net Building Controls' started by Rory, Jul 23, 2003.

  1. Rory

    Rory Guest

    I am creating a composite control that contains an iframe.
    I am creating this iframe in the 'CreateChildControls()'
    method by adding a literal control with its definition. I
    also have a hidden field (named using mybase.ID), which i
    used to populate with the controls 'Text' property.

    The problem I am having is when I first enter some content
    into the iframe and then trigger postback, it seems to
    save the content fine (i write the Text property value in
    the containing webform). However, the iframes content is
    blank. I then re-enter more content and trigger postback a
    second time. This time, the old content is populated in
    the iframe, and the new content I just entered is being
    saved (this is what appears when I write out the value of
    Text in the containng webform). I can keep triggering
    postback and these two entered values keep swapping.

    Does anyone know what is happening here?
    Thanks
     
    Rory, Jul 23, 2003
    #1
    1. Advertising

  2. Rory

    Teemu Keiski Guest

    Post some code how you have implemented the control. Basically you store
    data into ViewState?

    --
    Teemu Keiski
    MCP, Designer/Developer
    Mansoft tietotekniikka Oy
    http://www.mansoft.fi

    AspInsiders Member, www.aspinsiders.com
    ASP.NET Forums Moderator, www.asp.net
    AspAlliance Columnist, www.aspalliance.com

    "Rory" <> wrote in message
    news:07a101c350e6$07d49ba0$...
    > I am creating a composite control that contains an iframe.
    > I am creating this iframe in the 'CreateChildControls()'
    > method by adding a literal control with its definition. I
    > also have a hidden field (named using mybase.ID), which i
    > used to populate with the controls 'Text' property.
    >
    > The problem I am having is when I first enter some content
    > into the iframe and then trigger postback, it seems to
    > save the content fine (i write the Text property value in
    > the containing webform). However, the iframes content is
    > blank. I then re-enter more content and trigger postback a
    > second time. This time, the old content is populated in
    > the iframe, and the new content I just entered is being
    > saved (this is what appears when I write out the value of
    > Text in the containng webform). I can keep triggering
    > postback and these two entered values keep swapping.
    >
    > Does anyone know what is happening here?
    > Thanks
     
    Teemu Keiski, Jul 23, 2003
    #2
    1. Advertising

  3. Rory

    Teemu Keiski Guest

    INamingContainer is needed for postback routing. I understand your issue,
    but could you provide more complete code? It would help to get better
    picture what you are doing.

    --
    Teemu Keiski
    MCP, Designer/Developer
    Mansoft tietotekniikka Oy
    http://www.mansoft.fi

    AspInsiders Member, www.aspinsiders.com
    ASP.NET Forums Moderator, www.asp.net
    AspAlliance Columnist, www.aspalliance.com


    "Rory" <> wrote in message
    news:098801c35100$74118160$...
    > Below is the property declaration for the Text property of
    > the control:
    >
    > ------------------------------------------------
    > <Bindable(True), Category("Appearance"), DefaultValue("")>
    > Property [Text]() As String
    > Get
    > 'If the property has been set
    > If Not IsNothing(Me.ViewState("Text")) Then
    > 'Return the setting
    > Return Me.ViewState("Text")
    > Else
    > Return ""
    > End If
    > End Get
    >
    > Set(ByVal Value As String)
    > ' Store the property setting
    > Me.ViewState("Text") = Value
    > End Set
    > End Property
    > ----------------------------------------------------
    >
    > Also, I am implementing the 'IPostBackDataHandler'
    > interface. I also have a button within this control which
    > I am trying to attach an event to. I can get the event
    > firing only if I implement the 'iNamingContainer'
    > interface. But by doing this causes the problem I
    > mentioned in my previous post. By removing
    > the 'INamingContainter' from the class declaration, the
    > postback works fine, but the button event doesn't fire.
    >
    > I hope that I have explained this clearly. I would just
    > like to know what exactly is going on, and if it is
    > possible to wire up the button event without using
    > the 'iNamingContainer' interface.
    >
    > Thanks.
    >
    >
    >
    >
    > >-----Original Message-----
    > >Post some code how you have implemented the control.

    > Basically you store
    > >data into ViewState?
    > >
    > >--
    > >Teemu Keiski
    > >MCP, Designer/Developer
    > >Mansoft tietotekniikka Oy
    > >http://www.mansoft.fi
    > >
    > >AspInsiders Member, www.aspinsiders.com
    > >ASP.NET Forums Moderator, www.asp.net
    > >AspAlliance Columnist, www.aspalliance.com
    > >
    > >"Rory" <> wrote in message
    > >news:07a101c350e6$07d49ba0$...
    > >> I am creating a composite control that contains an

    > iframe.
    > >> I am creating this iframe in the 'CreateChildControls()'
    > >> method by adding a literal control with its definition.

    > I
    > >> also have a hidden field (named using mybase.ID), which

    > i
    > >> used to populate with the controls 'Text' property.
    > >>
    > >> The problem I am having is when I first enter some

    > content
    > >> into the iframe and then trigger postback, it seems to
    > >> save the content fine (i write the Text property value

    > in
    > >> the containing webform). However, the iframes content is
    > >> blank. I then re-enter more content and trigger

    > postback a
    > >> second time. This time, the old content is populated in
    > >> the iframe, and the new content I just entered is being
    > >> saved (this is what appears when I write out the value

    > of
    > >> Text in the containng webform). I can keep triggering
    > >> postback and these two entered values keep swapping.
    > >>
    > >> Does anyone know what is happening here?
    > >> Thanks

    > >
    > >
    > >.
    > >
     
    Teemu Keiski, Jul 23, 2003
    #3
  4. Rory

    Rory Guest

    Thanks for your replies.

    I have actually acheived postback events without
    implementing INamingContainer like so:

    ----- In 'CreateChildControl' method --------------
    Controls.Add(New LiteralControl("<input type=button
    value=Upload OnClick=""jscript:" &
    Page.GetPostBackEventReference(Me, "Upload") & """>"))
    ---------------------------------------------------

    I then am capturing this using:
    -------------------------------------------------
    Public Sub RaisePostBackEvent(ByVal EventArgument As
    String) Implements IPostBackEventHandler.RaisePostBackEvent
    If (EventArgument = "Upload") Then
    Me.Text = Me.Text & "<br>Upload Called."
    UploadFiles(Controls(5))
    End If
    End Sub
    --------------------------------------------------

    I appreciate your interest, and apologise because my
    problem now has changed from the original post. My problem
    now is maintaining the state of an HtmlInputFile control
    that I am adding to the control.

    eg.
    ------ in the 'CreateChildControls' method -------
    imgUpload = New System.Web.UI.HtmlControls.HtmlInputFile()
    Controls.Add(imgUpload)
    -------------------------------------

    I am not sure the best way to maintain the state of this.
    ie how do i capture the postback value

    Thanks again.





    >-----Original Message-----
    >INamingContainer is needed for postback routing. I

    understand your issue,
    >but could you provide more complete code? It would help

    to get better
    >picture what you are doing.
    >
    >--
    >Teemu Keiski
    >MCP, Designer/Developer
    >Mansoft tietotekniikka Oy
    >http://www.mansoft.fi
    >
    >AspInsiders Member, www.aspinsiders.com
    >ASP.NET Forums Moderator, www.asp.net
    >AspAlliance Columnist, www.aspalliance.com
    >
    >
    >"Rory" <> wrote in message
    >news:098801c35100$74118160$...
    >> Below is the property declaration for the Text property

    of
    >> the control:
    >>
    >> ------------------------------------------------
    >> <Bindable(True), Category("Appearance"), DefaultValue

    ("")>
    >> Property [Text]() As String
    >> Get
    >> 'If the property has been set
    >> If Not IsNothing(Me.ViewState("Text")) Then
    >> 'Return the setting
    >> Return Me.ViewState("Text")
    >> Else
    >> Return ""
    >> End If
    >> End Get
    >>
    >> Set(ByVal Value As String)
    >> ' Store the property setting
    >> Me.ViewState("Text") = Value
    >> End Set
    >> End Property
    >> ----------------------------------------------------
    >>
    >> Also, I am implementing the 'IPostBackDataHandler'
    >> interface. I also have a button within this control

    which
    >> I am trying to attach an event to. I can get the event
    >> firing only if I implement the 'iNamingContainer'
    >> interface. But by doing this causes the problem I
    >> mentioned in my previous post. By removing
    >> the 'INamingContainter' from the class declaration, the
    >> postback works fine, but the button event doesn't fire.
    >>
    >> I hope that I have explained this clearly. I would just
    >> like to know what exactly is going on, and if it is
    >> possible to wire up the button event without using
    >> the 'iNamingContainer' interface.
    >>
    >> Thanks.
    >>
    >>
    >>
    >>
    >> >-----Original Message-----
    >> >Post some code how you have implemented the control.

    >> Basically you store
    >> >data into ViewState?
    >> >
    >> >--
    >> >Teemu Keiski
    >> >MCP, Designer/Developer
    >> >Mansoft tietotekniikka Oy
    >> >http://www.mansoft.fi
    >> >
    >> >AspInsiders Member, www.aspinsiders.com
    >> >ASP.NET Forums Moderator, www.asp.net
    >> >AspAlliance Columnist, www.aspalliance.com
    >> >
    >> >"Rory" <> wrote in message
    >> >news:07a101c350e6$07d49ba0$...
    >> >> I am creating a composite control that contains an

    >> iframe.
    >> >> I am creating this iframe in the 'CreateChildControls

    ()'
    >> >> method by adding a literal control with its

    definition.
    >> I
    >> >> also have a hidden field (named using mybase.ID),

    which
    >> i
    >> >> used to populate with the controls 'Text' property.
    >> >>
    >> >> The problem I am having is when I first enter some

    >> content
    >> >> into the iframe and then trigger postback, it seems

    to
    >> >> save the content fine (i write the Text property

    value
    >> in
    >> >> the containing webform). However, the iframes

    content is
    >> >> blank. I then re-enter more content and trigger

    >> postback a
    >> >> second time. This time, the old content is populated

    in
    >> >> the iframe, and the new content I just entered is

    being
    >> >> saved (this is what appears when I write out the

    value
    >> of
    >> >> Text in the containng webform). I can keep triggering
    >> >> postback and these two entered values keep swapping.
    >> >>
    >> >> Does anyone know what is happening here?
    >> >> Thanks
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
     
    Rory, Jul 23, 2003
    #4
    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. sleigh
    Replies:
    1
    Views:
    2,705
    sleigh
    Feb 12, 2004
  2. Mark Olbert
    Replies:
    1
    Views:
    5,269
    Steven Cheng[MSFT]
    Feb 23, 2006
  3. Chad
    Replies:
    0
    Views:
    236
  4. Amit
    Replies:
    0
    Views:
    863
  5. whoisnidhee

    ViewState of the Composite Control composed of custom control

    whoisnidhee, Jul 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    327
    Nidhee
    Jul 16, 2004
Loading...

Share This Page