Search code examples
asp.netcode-behindcreateuserwizard

Show CreateUserWizard's error message label


I've got a CreateUserWizard control and am performing server-side validation. Is there a way to force the CUW's error message to display from the code-behind? At the moment, if the user enters a duplicate name, the controls DuplicateUserNameErrorMessage property is displayed. However, if the user has turned javascript off, or sends a custom POST header, with invalid characters, I rely on my server-side validation to catch the error. How can I then display the same error message in the control's ErrorMessage label, instead of creating a custom label and faking it?

Edit: Just to clarify, the server side validation tests various aspects. Duplicate user was just an example of when the ErrorMessage label gets called by the control.

Thanks


Solution

  • Update:

    Here is something that will work, but requires private reflection:

    void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e) {
        typeof(CreateUserWizard).GetField(
            "_unknownErrorMessage",
            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
            .SetValue(sender, "My error message");
        e.Cancel = true;
    }
    

    Basically, you set this field to the error message you want, and CreateUserWizard picks it up. Being private reflection, it's not a 'supported' technique, but it's at least an option to consider if nothing else works.


    I don't think you should have to do anything special for this to work. Generally, anything that supports client side validation has matching server side validation logic. In fact, for something like duplicate name, there is only server side validation, so I wouldn't think that turning off javascript should affect the scenario.

    What exactly are you seeing when you disable javascript and you post a duplicate name? ARe you able to repro this issue with a simple page, or is there some added factors that could affect it?

    I tried with a plain CUW and disabled javascript, and the duplicate user error was correctly displayed.