Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

Problem in validation control

Hi

I have created the validation summary control dynamically(see code section)


even if validation fails I am not able to see the validation
ValidationSummary oValidationSummary = new ValidationSummary();
                    oValidationSummary.ID = "val";
                    oValidationSummary.DisplayMode = ValidationSummaryDisplayMode.BulletList;
                    oValidationSummary.EnableClientScript = true;
                    oValidationSummary.ShowSummary = true;
                    
 
                    CustomValidator oCustomValidator = new CustomValidator();
                    oCustomValidator.ID = "cvName";
                    oCustomValidator.Visible = true;
                    oCustomValidator.ControlToValidate = ID;
                    oCustomValidator.Enabled = true;
                    oCustomValidator.ValidateEmptyText = true;
                    oCustomValidator.ErrorMessage = MTBErrorMessage;
 
                    oCustomValidator.ServerValidate += new ServerValidateEventHandler(oCustomValidator_ServerValidate);
 
void oCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            Validation oValidation = new Validation();
            bool status = true;
            status = oValidation.IsValid(MTBValidationType, Text);
 
            args.IsValid = status;
}

Open in new window

Avatar of Muhammad Ousama Ghazali
Muhammad Ousama Ghazali
Flag of Saudi Arabia image

Dynamically created controls should be added from within the Page_Init event even on postbacks, otherwise there expected events would not fire.
Let me get back to you with a link to a recent discussion on EE on about the same matter.
Avatar of KaranGupta
KaranGupta

ASKER

Can we add Page_Init event in web custom control
If you are asking about WebUserControl, then yeah surely you can add. And if you are Custom Web Server Controls, I think it should allow you to have this.
I have implemented in that way(code section)

but the debugging control is not going on Page init
private void Page_Init(object sender, EventArgs e)
        {
            if (MTBErrorMessageControlType == MTBErrorMessageControl.VALIDATIONSUMMARY)
            {
                ValidationSummary oValidationSummary = new ValidationSummary();
                oValidationSummary.ID = "val";
                oValidationSummary.DisplayMode = ValidationSummaryDisplayMode.BulletList;
                oValidationSummary.EnableClientScript = true;
                oValidationSummary.ShowSummary = true;
 
 
                CustomValidator oCustomValidator = new CustomValidator();
                oCustomValidator.ID = "cvName";
                oCustomValidator.Visible = true;
                oCustomValidator.ControlToValidate = ID;
                oCustomValidator.Enabled = true;
                oCustomValidator.ValidateEmptyText = true;
                oCustomValidator.ErrorMessage = MTBErrorMessage;
                oCustomValidator.ServerValidate += new ServerValidateEventHandler(oCustomValidator_ServerValidate);
            }
        }
        void oCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            Validation oValidation = new Validation();
            bool status = true;
            status = oValidation.IsValid(MTBValidationType, Text);
 
 
            args.IsValid = status;
 
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Muhammad Ousama Ghazali
Muhammad Ousama Ghazali
Flag of Saudi Arabia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi

Debugging is enabled as I am able to get the control on Render() method
I just tested at my machine in VS2008 that the Page_Init on a WebUserControl is being debugged by the Debugger. Please look into the settings of VS2008 Debugger.