Passing property value to custom control

C

Chris Kennedy

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.

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 it works fine.
 
S

Scott Mitchell [MVP]

Chris said:
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.
//
It is like on the postback the XML value is not being passed to the
control again.

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
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
H

Henri

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 ?
 
S

Scott Mitchell [MVP]

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

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
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top