Groups | Blog | Home
all groups > asp.net building controls > may 2004 >

asp.net building controls : Passing property value to custom control


Chris Kennedy
5/11/2004 8:00:39 PM
I have a custom control which uses an XML file in the =
CreateChildControls event, the XML file is used to determine how many =
and what composite form elements to add. I can set the path to a =
different XML file on Page_Load event of the parent page. When I press a =
button even if contains no code it triggers a postback (which is =
normal). Even though I am resetting the location value in Page_load =
event I get a "The path is not of a legal form" error.=20

It is like on the postback the XML value is not being passed to the =
control again. Ideally I want to point the control at different XML =
files and set this property from various different buttons. Is there =
somehthing I don't understand about the state in the control. I thought =
it would reinstantiated after each postback. And I would just be able to =
set in the Page_load event. When I hardcode the XML path to the XML file =
Scott Mitchell [MVP]
5/11/2004 8:47:34 PM
[quoted text, click to view]

Are you setting the path initially in Page_Load like so:

If Not Page.IsPostBack then
myControl.XmlPath = ...
End If

???

If so, are you sure that you're control is saving this value in tbe view
state? That is, does the property for XmlPath in your control look like:

Public Property XmlPath as String
Get
Dim o as Object = ViewState("XmlPath")
If o is Nothing then
Return String.Empty
Else
Return o.ToString()
End If
End Get
Set
ViewState("XmlPath") = Value
End Set
End Property

???



--

Scott Mitchell
mitchell@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

Chris Kennedy
5/12/2004 9:07:42 PM
I am a bit of a newbie and this is a trickier bit of .net. What you =
suggested worked to a certain extent. You were right I wasn't using the =
viewstate, I thought the INaming container remembered the properties. =
What happens is=20
If Not Page.IsPostBack Then

CompControl1.Location =3D "C:\Inetpub\wwwroot\AVTest\XMLFile2.xml"

End If

in the parent page. Then in one of the buttons on the page I

CompControl1.Location =3D "C:\Inetpub\wwwroot\AVTest\XMLFile1.xml"

It doesn't do anything on the first click but changes the XML value on =
the second click, i.e. I can see the different controls created in the =
createchildcontrols() event based on values in the XML file. I have =
another button which sets the valu back which when I click it back twice =
on the second time creates an invalid cast error, like it is being given =
a null value instead of a string. I have even tried setting the value of =
a session or viewstate in the buttons and reading them in the page load =
event.

If Not Page.IsPostBack Then

CompControl1.Location =3D "C:\Inetpub\wwwroot\AVTest\XMLFile2.xml"

End If

If Not IsNothing(Ssesion("XMLPath")) Then

CompControl1.Location =3D Session("XMLPath")

End If

Any ideas. Regards, Chris


[quoted text, click to view]
Henri
5/15/2004 11:03:36 PM
Just a different question :
Is it possible to pass directly the XmlDocument object as a property rather
than the path ?

I would like to use sth like :
<namespace:control runat="server" id="id" document="myXmlDocumentObj" />

Is it possible to pass an object as a property ?



"Scott Mitchell [MVP]" <mitchell@4guysfromrolla.com> a écrit dans le message
de news:GZaoc.7291$gm5.2802@newssvr27.news.prodigy.com...
[quoted text, click to view]


Scott Mitchell [MVP]
5/18/2004 5:11:32 PM
[quoted text, click to view]

Yes, it's possible, but not declaratively. That is, you could do:

<namespace:control runat="server" id="id" />

and then in the code do:

id.document = myXmlDocumentObj

Happy Programming!

--

Scott Mitchell
mitchell@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

AddThis Social Bookmark Button