Share via


State Management Service Example

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In the following example, the Web Part, Get More Information, tracks the requester's name and address, so it can be retrieved the next time the user accesses the dashboard. It stores these values in custom properties using the State Management service. For each property, the Web Part specifies the namespace and name in addition to the value for each property.

Later, the Web Part can retrieve this state through the Properties collection.

The following is the content of the Web Part, Purchase Car.

**Note   **The Web Part uses the string 'varPart_WPQ_' to reference itself.

<TABLE border=0 cellPadding=1 cellSpacing=1 style="HEIGHT: 228px; WIDTH: 415px" width="75%">
  <TR>
    <TD>Name:</TD>
    <TD><INPUT id=txtName_WPQ_ style="HEIGHT: 22px; WIDTH: 278px"></TD></TR>
   …
</TABLE>
</P>
<INPUT id=load_WPQ_ type=button value="Remember Me" LANGUAGE=javascript onclick="load_WPQ__onclick();">
<INPUT id=save_WPQ_ type=button value="Place Order" LANGUAGE=javascript onclick="save_WPQ__onclick();">
<SCRIPT LANGUAGE="javascript">
function save_WPQ__onclick() {
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#CustName").Value = 
      txtName_WPQ_.value;
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#Address1").Value = 
      txtAddress1_WPQ_.value;
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#Address2").Value = 
      txtAddress2_WPQ_.value;
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#City").Value = 
      txtCity_WPQ_.value;
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#State").Value = 
      txtState_WPQ_.value;
   varPart_WPQ_.Properties.Add("urn:myCompany:Custinfo#Zip").Value = 
      txtZip_WPQ_.value;
   varPart_WPQ_.Save();
}
function load_WPQ__onclick() {
   txtName_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#CustName").Value;
   txtAddress1_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#Address1").Value;
   txtAddress2_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#Address2").Value;
   txtCity_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#City").Value;
   txtState_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#State").Value;
   txtZip_WPQ_.value = 
   varPart_WPQ_.Properties.Item("urn:myCompany:Custinfo#Zip").Value;
}
</SCRIPT>

See Also

State Management Service | Part Object (State Management Service) | Dashboard Object (State Management Service) | Property Object (State Management Service) | PropertyCollection Object (State Management Service)