System.Web.UI.WebControls.ObjectDataSource.UpdateMethod Property

Gets or sets the name of the method or function that the System.Web.UI.WebControls.ObjectDataSource control invokes to update data.

Syntax

[System.ComponentModel.DefaultValue("")]
public string UpdateMethod { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The System.Web.UI.WebControls.ObjectDataSource control assumes that the method that is identified by the ObjectDataSource.UpdateMethod property performs updates one at a time, rather than in a batch.

The ObjectDataSource.UpdateMethod property delegates to the ObjectDataSourceView.UpdateMethod property of the System.Web.UI.WebControls.ObjectDataSourceView object that is associated with the System.Web.UI.WebControls.ObjectDataSource control.

Make sure that the parameter names configured for the System.Web.UI.WebControls.ObjectDataSource control in the ObjectDataSource.UpdateParameters collection match the column names that are returned by the select method.

Object Lifetime

The method that is identified by the ObjectDataSource.UpdateMethod property can be an instance method or a static (Shared in Visual Basic) method. If it is an instance method, the business object is created and destroyed each time the method that is specified by the ObjectDataSource.UpdateMethod property is called. You can handle the ObjectDataSource.ObjectCreated and ObjectDataSource.ObjectCreating events to work with the business object before the method that is specified by the ObjectDataSource.UpdateMethod property is called. You can also handle the ObjectDataSource.ObjectDisposing event that is raised after the method that is specified by the ObjectDataSource.UpdateMethod property is called. If the business object implements the IDisposable interface, the IDisposable.Dispose method is called before the object is destroyed. If the method is static (Shared in Visual Basic), the business object is never created and you cannot handle the ObjectDataSource.ObjectCreated, ObjectDataSource.ObjectCreating, and ObjectDataSource.ObjectDisposing events.

Parameter Merging

Parameters are added to the ObjectDataSource.UpdateParameters collection from three sources:

  • From the data-bound control, at run time.

  • From the UpdateParameters element, declaratively.

  • From the ObjectDataSource.Updating event handler, programmatically.

First, any parameters that are generated from data-bound controls are added to the ObjectDataSource.UpdateParameters collection. For example, if the System.Web.UI.WebControls.ObjectDataSource control is bound to a System.Web.UI.WebControls.GridView control that has the columns Name and Number, the parameters for Name and Number are added to the collection. The exact name of the parameter depends on the ObjectDataSource.OldValuesParameterFormatString property. The data type of these parameters is string. Next, the parameters that are listed in the UpdateParameters element are added. If a parameter in the UpdateParameters element is found with the same name as a parameter that is already in the ObjectDataSource.UpdateParameters collection, the existing parameter is modified to match the parameter that is specified in the UpdateParameters element. Typically, this is used to modify the type of the data in the parameter. Finally, you can programmatically add and remove parameters in the ObjectDataSource.Updating event, which occurs before the ObjectDataSource.Update method is run. The method is resolved after the parameters are merged. Method resolution is discussed in the next section.

Note:

You should validate any parameter value that you receive from the client. The runtime simply substitutes the parameter value into the ObjectDataSource.UpdateMethod property.

Method Resolution

When the ObjectDataSource.Update method is called, the data fields from the data-bound control, the parameters that were created declaratively in the UpdateParameters element, and the parameters that were added in the ObjectDataSource.Updating event handler are all merged. (For more information, see the preceding section.) The System.Web.UI.WebControls.ObjectDataSource control then attempts to find a method to call. First, it looks for one or more methods with the name that is specified in the ObjectDataSource.UpdateMethod property. If no match is found, an InvalidOperationException exception is thrown. If a match is found, it then looks for matching parameter names. For example, suppose a type that is specified by the ObjectDataSource.TypeName property has two methods named UpdateARecord. One UpdateARecord has one parameter, ID, and the other UpdateARecord has two parameters, Name and Number. If the ObjectDataSource.UpdateParameters collection has only one parameter named ID, the UpdateARecord method with just the ID parameter is called. The type of the parameter is not checked in resolving the methods. The order of the parameters does not matter.

If the ObjectDataSource.DataObjectTypeName property is set, the method is resolved in a different way. The System.Web.UI.WebControls.ObjectDataSource looks for a method with the name that is specified in the ObjectDataSource.UpdateMethod property that takes one parameter of the type that is specified in the ObjectDataSource.DataObjectTypeName property. In this case, the name of the parameter does not matter.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0