ObjectDataSourceView.UpdateMethod Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the name of the method or function that the ObjectDataSourceView object invokes to update data.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public string UpdateMethod { get; set; }

Property Value

Type: System.String

A string that represents the name of the method or function that the ObjectDataSourceView uses to update data. The default is an empty string ("").

The ObjectDataSourceView object assumes that the method that is identified by the UpdateMethod property performs updates one at a time, rather than in a batch.

The method 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 specified by the UpdateMethod property is called. You can handle the ObjectCreated event to work with the business object before the method specified by the UpdateMethod property is called. You can also handle the ObjectDisposing event that is raised after the UpdateMethod method is called. (Dispose is called, only if the business object implements the IDisposable interface.) If the method is a static (Shared in Visual Basic) method, the business object is never created and you cannot handle these events.

If the business object that the ObjectDataSource object works with implements more than one method or function with the same name (method overloads), the data source control attempts to invoke the correct one according to a set of conditions, including the parameters in the UpdateParameters collection. If the parameters in the UpdateParameters collection do not match those of the signature of the method specified by the UpdateMethod property, the data source throws an exception.

For more information, see ObjectDataSource.UpdateMethod.

The value of the UpdateMethod property is stored in view state.

The following code example demonstrates how to use a DropDownList control, TextBox controls, and several ObjectDataSource controls to update data. The DropDownList displays the name of a NorthwindEmployee, while the TextBox controls are used to enter and update address information. Because the UpdateParameters collection contains a ControlParameter object that is bound to the selected value of the DropDownList, the button that triggers the Update operation is enabled only after an employee is selected.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

// Add parameters and initialize the user interface
// only if an employee is selected.
private void Page_Load(object sender, EventArgs e)
  // Be sure the text boxes are initialized with
  // data from the currently selected employee.
  NorthwindEmployee selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue);
  if (selectedEmployee != null) {
    AddressBox.Text    = selectedEmployee.Address;
    CityBox.Text       = selectedEmployee.City;
    PostalCodeBox.Text = selectedEmployee.PostalCode;

    Button1.Enabled = true;
  else {
    Button1.Enabled = false;

// Press the button to update.
private void Btn_UpdateEmployee (object sender, CommandEventArgs e) {
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>ObjectDataSource - C# Example</title>
    <form id="Form1" method="post" runat="server">

        <!-- The DropDownList is bound to the first ObjectDataSource. -->
          typename="Samples.AspNet.CS.EmployeeLogic" />

          autopostback="True" /></p>

        <!-- The second ObjectDataSource performs the Update. This
             preserves the state of the DropDownList, which otherwise
             would rebind when the DataSourceChanged event is
             raised as a result of an Update operation. -->

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client.
             Security Note: To validate the value of the FormParameter,
             Security Note: handle the Updating event. -->

            <asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
            <asp:formparameter name="anAddress" formfield="AddressBox" />
            <asp:formparameter name="aCity" formfield="CityBox" />
            <asp:formparameter name="aPostalCode" formfield="PostalCodeBox" />

          runat="server" /></p>

          runat="server" /></p>

          runat="server" /></p>

          text="Update Employee"
          oncommand="Btn_UpdateEmployee" />


.NET Framework
Available since 2.0
Return to top