Microsoft KB Archive/309084

= PRB: &quot;Command Must Be Contained Within a Form&quot; Error Message When You View Mobile Web Form in Browser =

Article ID: 309084

Article Last Modified on 8/6/2002

-

APPLIES TO


 * Microsoft Mobile Internet Toolkit 1.0

-



This article was previously published under Q309084



SYMPTOMS
If the following conditions are true
 * A mobile Web Form contains a templated mobile ObjectList control. -and-


 * The ObjectList control contains a mobile Command control with a Click event. -and-


 * You view the mobile Web Form in your browser.

you may receive the following error message:

System.Exception: The control with id _ct : of type Command must be contained within a Form.

where  varies depending on the number of controls on the page and where   is the ID property of the Command control.



CAUSE
When you use a data bound ObjectList control, if the DataBind method of the control is called on postback, the controls from the initial creation of the page are removed from the control tree. A new set of controls is added to the control tree and is data bound. You receive this error message because the Click event of the Command control is routed to the original control, which no longer exists in the control tree.



RESOLUTION
You do not have to call the DataBind method on the ObjectList control for each postback to the server to repopulate the data in the control. The ObjectList maintains its own ViewState property and repopulates the data automatically.

If you must call the DataBind method on postback, call it in the Page_Init event or in the Item_Command event of the ObjectList control. You can use the Item_Command event to handle Click event of Command controls.



STATUS
This behavior is by design.

Additional query words: DataBind browse

Keywords: kbnofix kbstate kbprb kbservercontrols KB309084

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.