Share via


ClientViewState

  Microsoft Speech Technologies Homepage

In their simplest form, ASP.NET pages are stateless. They are instantiated, executed, rendered, and disposed of on every round trip to the server. In a visual environment, ASP.NET provides the ViewState mechanism to keep track of server control state values that do not otherwise post values back as part of an HTTP form. ASP.NET applications use ViewState to manage and restore server-side data prior to and after postback. For more information on ViewState, see Maintaining State in a Control.

The ASP.NET ViewState mechanism is not applicable to client-side data, but the client-side SpeechCommon object maintains ClientViewState as a client-side counterpart to ViewState. ClientViewState stores client-side String values that authors want to persist across postbacks. Authors should convert data of types other than String to String variables before saving in ClientViewState.

If AutoPostBack is set to true in any Speech Control, the matching client-side function will always be executed before posting back to the server. If the author wants to persist any page state across postback, these client-side functions are a good place to invoke the ClientViewState object of SpeechCommon.

Example

The following example demonstrates the ClientActivationFunction property of a QA control maintaining a number called "noReco." This number is maintained through successive activations of the QA control, and incremented whenever the most recent element of the Command/Exception History is "NoReco" or "Silence."

//Keeps track of silence and no reco and stops if count greater than three.
function selectionActivation(QAObject)
{
    var AllowedErrors = 3;
    var CountedErrors;

    var lceIndex = RunSpeech.ActiveQA.History.length - 1;
    var lceData = RunSpeech.ActiveQA.History[lceIndex];

    if(typeof(SpeechCommon.GetViewState("noReco")) == "undefined") {
        SpeechCommon.SetViewState("noReco", "0");
    }
    if(lceData == "Silence" || lceData == "NoReco") {
        CountedErrors = parseInt(SpeechCommon.GetViewState("RecoErrs"), 10) + 1;
        SpeechCommon.SetViewState("RecoErrs", (CountedErrors).toString());
    }
    if(CountedErrors > AllowedErrors) {
      return false;
    }
    return true;
}