/// <summary>
 /// Executed every time page is loaded. Checks for OpenID-related requests,
 /// and processes, if present.
 /// </summary>
 /// <param name="sender">Object invoking this method.</param>
 /// <param name="e">EventArgs associated with the request.</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     // need to store openid, email, newsletter bool etc. in database for first time user.
     if (!IsPostBack)
     {
         OpenIDConsumer openid = new OpenIDConsumer();
         switch (openid.RequestedMode) {
             case RequestedMode.IdResolution:
                 openid.Identity = this.Identity;
                 SetAuthMode(openid);
                 if (openid.Validate())
                 {
                     _UserObject = openid.RetrieveUser();
                     FormPanel.Visible = false;
                     StatusPanel.Visible = true;
                     OnValidateSuccess(e);
                 }
                 else
                 {
                     FormPanel.Visible = true;
                     StatusPanel.Visible = false;
                     LLabel.Text = openid.GetError();
                     OnValidateFail(e);
                 }
                 break;
             case RequestedMode.CancelledByUser:
                 FormPanel.Visible = true;
                 StatusPanel.Visible = false;
                 LLabel.Text = "Login request cancelled.";
                 OnRemoteCancel(e);
                 break;
             case RequestedMode.None:
                 if (UserObject != null)
                 {
                     FormPanel.Visible = false;
                     StatusPanel.Visible = true;
                 }
                 break;
         }
     }
 }
    /// <summary>
    /// User has clicked the login button. Sets up a new OpenIDConsumer
    /// object and begins the authentication sequence. 
    /// Fires the OnLogin event. 
    /// </summary>
    /// <param name="sender">Object invoking this method.</param>
    /// <param name="e">EventArgs related to this request.</param>
    protected void Button_Click(object sender, EventArgs e)
    {
        OpenIDConsumer openid = new OpenIDConsumer();
        SetAuthMode(openid);
        SimpleRegistration sr = new SimpleRegistration(openid);
        if (this.RequiredFields != null) { sr.RequiredFields = this.RequiredFields; }
        if (this.OptionalFields != null) { sr.OptionalFields = this.OptionalFields; }
        if (this.PolicyURL != null) { sr.PolicyURL = this.PolicyURL; }
        openid.Identity = openid_url.Text;
        this.Identity = openid.Identity;
        OnLogin(e);
        openid.BeginAuth();

        if (openid.IsError())
        {
            LLabel.Text = openid.GetError();
        }
        else
        {
            LLabel.Text = "";
        }
    }