PRB: "Command Must Be Contained Within a Form" Error Message When You View Mobile Web Form in Browser (309084)
The information in this article applies to:
- Microsoft Mobile Internet Toolkit (MMIT)
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 _ctxx:Command1 of type Command must be contained within a Form.
where xx varies depending on the number of controls on the page and where Command1 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.
STATUSThis behavior is by design.
Modification Type: | Major | Last Reviewed: | 8/6/2002 |
---|
Keywords: | kbDSupport kbprb kbServerControls kbState KB309084 |
---|
|