StateBag.Remove Method (String)

 

Removes the specified key/value pair from the StateBag object.

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

public void Remove(
	string key
)

Parameters

key
Type: System.String

The item to remove.

The following code example demonstrates using the Remove method.

void MovePiece(string fromPosition, string toPosition) {
   StateBag bag = ViewState;
   object piece = bag[fromPosition];
   if (piece != null) {
      bag.Remove(fromPosition);
      bag.Add(toPosition, piece);
      RenderBoard();
   }
   else {
      throw new InvalidPositionException("There is no game piece at the \"from\" position."); 
   }
}

.NET Framework
Available since 1.1
Return to top
Show: