This documentation is archived and is not being maintained.

Triplet Class

Holds three objects that can be added together to an ASP.NET server control's view state.

For a list of all members of this type, see Triplet Members.

System.Object
   System.Web.UI.Triplet

[Visual Basic]
Public Class Triplet
[C#]
public class Triplet
[C++]
public __gc class Triplet
[JScript]
public class Triplet

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

You can add this object to a server control's view state in the same way that you add a single object to view state. This class offers a more efficient way of adding groups of objects to a server control's view state. For more information, see Maintaining State in a Control.

Example

[Visual Basic] The following example creates a method that adds three objects to view state using the Triplet class. It then creates a method to retrieve them and displays the values to a page.

[Visual Basic] 
' When a button is clicked, this method creates an instance of
' the Triplet class, named myTriplet, adds it to the page's ViewState property,
' and displays user selections in a label.
Sub btnAddToViewState_Click(sender As [Object], e As EventArgs)

    ' This example demonstrates the Triplet(Object, Object, Object) constructor.
    Dim myTriplet As New Triplet(triTextBox.Text, triDDList.SelectedItem.Text, triRBList.SelectedItem.Text)
    ViewState("triplet1")= myTriplet

    triLabel1.Text = "Your inputs: " & _
       triTextBox.Text & ", " & _
       triDDList.SelectedItem.Text & ", and " & _
       triRBList.SelectedItem.Text & "."


End Sub 'btnAddToViewState_Click

' When a button is clicked, this method retrieves values from
' view state that were added using an instance of the Triplet class.
Sub btnRetrieve_Click(sender As [Object], e As EventArgs)
    ' Create variables to store the retrieved strings.
    Dim firstValue As String
    Dim secondValue As String
    Dim thirdValue As String

    ' Use the empty Triplet constructor to create a new instance
    ' of the class, and then set it equal to the value stored
    ' in view state.
    Dim o As Object = ViewState("triplet1")

    If o is Nothing
       triLabel2.Text = "There is no triplet1 key stored in view state."
    Else
       Dim myTriplet1 As Triplet = CType(o, Triplet)
       firstValue = CStr(myTriplet1.First)
       secondValue = CStr(myTriplet1.Second)
       thirdValue = CStr(myTriplet1.Third)

       triLabel2.Text = "You retrieved " & _
        firstValue & ", " & _
        secondValue & ", and " & _
        thirdValue & " from view state."
    End If

End Sub 'btnRetrieve_Click

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

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

See Also

Triplet Members | System.Web.UI Namespace | ViewState

Show: