ViewState Problem with Composite Control

R

Rory

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
 
T

Teemu Keiski

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 said:
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




.
 
R

Rory

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 said:
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

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


.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top