Wednesday, March 21, 2012

Declarative Markup within a server control

I'm creating an address control that is utilizing Atlas in a couple of places. The first place I use it I've got the javascript functions working fine. (It auto fills the address based on the zip code.)
After the autofill, the user is allowed to type in changes as needed. I was going to use the autocomplete in the state portion, and was going to use the declarative markup similar to the HOLs. When putting two of the controls on a page I was registering two declarative blocks, and they don't work. I tested it in straight HTML outside the control and got the same result. However, in the HTML test I combined it to one block (below) and it works fine.
My problem is how to get the control to render one block of declarative markup if more than one of the same control exists.
Script

<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
<!-- Repath the following src attributes, using regular client relative paths as necessary -->
<add src="ScriptLibrary/AtlasUI.js" />
<add src="ScriptLibrary/AtlasControls.js" />
</references>
<components>
<textBox id="Address2_txtState">
<behaviors>
<autoComplete
completionList="completionList"
serviceURL="Services/AddressAutoComplete.asmx"
serviceMethod="GetStateList"
minimumPrefixLength="1"
completionSetCount="10"
completionInterval="500" />
</behaviors>
</textBox>
<textBox id="Address2_txtState">
<behaviors>
<autoComplete
completionList="completionList"
serviceURL="Services/AddressAutoComplete.asmx"
serviceMethod="GetStateList"
minimumPrefixLength="1"
completionSetCount="10"
completionInterval="500" />
</behaviors>
</textBox>
</components>
</page>
</script>


I don't think I exactly understand your problem. Could you maybe share the code that resulted in "two declarative blocks"?

My original design created one declarative block per server control. As long as I only have one control, that works fine. As soon as I drop the second one on the page, neither of them work because I get two blocks (below), rather than the one block needed in my original post.

<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
<!-- Repath the following src attributes, using regular client relative paths as necessary -->
<add src="ScriptLibrary/AtlasUI.js" />
<add src="ScriptLibrary/AtlasControls.js" />
</references>
<components>
<textBox id="Address1_txtState">
<behaviors>
<autoComplete
completionList="completionList"
serviceURL="Services/AddressAutoComplete.asmx"
serviceMethod="GetStateList"
minimumPrefixLength="1"
completionSetCount="10"
completionInterval="500" />
</behaviors>
</textBox></components>
</page>
</script>

<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
<!-- Repath the following src attributes, using regular client relative paths as necessary -->
<add src="ScriptLibrary/AtlasUI.js" />
<add src="ScriptLibrary/AtlasControls.js" />
</references>
<components>
<textBox id="Address2_txtState">
<behaviors>
<autoComplete
completionList="completionList"
serviceURL="Services/AddressAutoComplete.asmx"
serviceMethod="GetStateList"
minimumPrefixLength="1"
completionSetCount="10"
completionInterval="500" />
</behaviors>
</textBox></components>
</page>
</script>


Interesting. All server-side Atlas controls should render their scripttags to 1 AtlasTextWriter, which will write the contents inside asingle script tag. At least that's what it is supposed to do.
Do you have a repro that results in the code you pasted?

As I understand it, you have created a custom composite server control? How are you rendering out the declartive block? Are you just string.building? Maybe you should look into this AtlasScriptWriter the other poster mentioned.

Does anyone have any more info on this AtlasScriptWriter (or AtlasTextWriter)? Is this the recommended method for rendering custom Atlas controls?

No comments:

Post a Comment