Hello,
So far I've found the threads here invaluable in the month that I have been using Telerik controls. Unfortunately I find myself in a situation where I cannot find an answer in an existing thread although I've tried to piece some solutions together.
I am using asp.net RegularExpressionValidators and RequiredFieldValidators when needed and they are set to display dynamically. My first task was to shade the invalid rad boxes when they are invalid. I accomplished this by using <ClientEvents> then setting the enabled style and calling updateCssClass. This is working great. The problem I am having now is that when the submit button is clicked, the client validation is firing but I can no longer set the background color. I'm using the onClientClick then looping through the validators and the rad input controls but I must be doing something wrong. When I step through the javascript I can see the EnabledStyle get set and the updateCssClass get called just like what is working when the individual textboxes work.
I'm only including one textbox in the aspx example for brevity.
Here is the code:
Javascript
ASPX
Any help is greatly appreciated!
Edit: I've also tried to use WebForm_OnSubmit() but that doesn't work either. When using Developer Tools in IE to look at the markup, the css is being overwritten by the time I see it.
So far I've found the threads here invaluable in the month that I have been using Telerik controls. Unfortunately I find myself in a situation where I cannot find an answer in an existing thread although I've tried to piece some solutions together.
I am using asp.net RegularExpressionValidators and RequiredFieldValidators when needed and they are set to display dynamically. My first task was to shade the invalid rad boxes when they are invalid. I accomplished this by using <ClientEvents> then setting the enabled style and calling updateCssClass. This is working great. The problem I am having now is that when the submit button is clicked, the client validation is firing but I can no longer set the background color. I'm using the onClientClick then looping through the validators and the rad input controls but I must be doing something wrong. When I step through the javascript I can see the EnabledStyle get set and the updateCssClass get called just like what is working when the individual textboxes work.
I'm only including one textbox in the aspx example for brevity.
Here is the code:
Javascript
function ValidateOnSubmit() { var allRadControls = $telerik.radControls; var isValid = true; for (var i = 0; i < Page_Validators.length; i++) { var val = Page_Validators[i]; ValidatorValidate(val, "all"); if (!val.isvalid) { isValid = false; for (var y = 0; y < allRadControls.length; y++) { if (val.controltovalidate == allRadControls[y]._clientID) { allRadControls[y].get_styles().EnabledStyle[0] += "background-color: LightPink;"; allRadControls[y].updateCssClass(); } } } else { isValid = true; } } }ASPX
<telerik:RadTextBox ID="radtbEmailAddress" runat="server" MaxLength="256" ValidationGroup="all" EmptyMessage="Enter Email Address" Width="225px"> <ClientEvents OnValueChanged="ValidatePage" /></telerik:RadTextBox><asp:RegularExpressionValidator id="revEmail" runat="server" ErrorMessage="Please, enter valid e-mail address." ValidationExpression= "^((?:(?:(?:[a-zA-Z0-9][\!\#\$\%\&\'\*\/\=\?\^\`\{\|\}\~\.\-\+_]?)*)[a-zA-Z0-9])+)\@((?:(?:(?:[a-zA-Z0-9][\!\#\$\%\&\'\*\/\=\?\^\`\{\|\}\~\.\-\+_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$" ControlToValidate="radtbEmailAddress" ForeColor="Red" Display="Dynamic" ValidationGroup="all" > </asp:RegularExpressionValidator><asp:RequiredFieldValidator ID="rfvEmailAddress" runat="server" ForeColor="Red" ControlToValidate="radtbEmailAddress" Display="Dynamic" ValidationGroup="all" ErrorMessage="Please enter an email address"></asp:RequiredFieldValidator> <br /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="ValidateOnSubmit();" OnClick="btnSubmit_Click" CssClass="brown" CausesValidation="true" ValidationGroup="all" />Any help is greatly appreciated!
Edit: I've also tried to use WebForm_OnSubmit() but that doesn't work either. When using Developer Tools in IE to look at the markup, the css is being overwritten by the time I see it.