This is a migrated thread and some comments may be shown as answers.

How to set Invalid Style on server side

3 Answers 179 Views
Input
This is a migrated thread and some comments may be shown as answers.
Li Zhou
Top achievements
Rank 1
Li Zhou asked on 24 Jun 2010, 06:25 PM
Can someone help me how t set invalid style in server side.  My code as as following.  When validate through client side, textbox style is set to invalid style(CssClass="InvalidTextBox") if validation fails.  Similarlly I want to do the validation in server side just in case client side validation does not go through.  How to set to Invalid style in server side ?

<

 

telerik:RadTextbox ID="Email" runat="server">

 

    <

 

EmptyMessageStyle CssClass="EmptyTextBox" />

 

 

 

 

 

    <EnabledStyle CssClass="EnabledTextBox" />

 

 

 

 

 

    <FocusedStyle CssClass="FocusedTextBox" />

 

 

 

 

 

    <HoveredStyle CssClass="HoveredTextBox" />

 

 

 

 

 

    <InvalidStyle CssClass="InvalidTextBox" />

 

 

 

</telerik:RadTextbox>
<

 

asp:CustomValidator runat="server" EnableClientScript="true" controltovalidate="Email" id="ev" ClientValidationFunction="ClientValidate" OnServerValidate="ServerValidate" />

 


function

 

ClientValidate(sender, args)
{

 

 

     var email = $find("<%= email.ClientID %>");

 

 

        if (! validate(email.get_value())) 
       {

 

            email._invalid =

true;

 

            email.updateCssClass();

            args.IsValid =

false;

 

        }

}


 

protected void ServerValidate(object source, ServerValidateEventArgs args)

 

{

 

    args.IsValid = validate(email.Text);

 

 

    if (!args.IsValid)

 

    {

 

        //how to set invalid style for email RadTextBox ????

 

 

    }
}

 

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 28 Jun 2010, 08:25 AM
Hi Li Zhou,

Probably the easiest way to achieve the desired behavior is to use an additional asp:HiddenField control to pass a flag to the client, then use the RadTextBox' Load client event, check the flag value, set the _invalid client property and execute updateCssClass(), as in the ClientValidate function.

http://www.telerik.com/help/aspnet-ajax/input_clientsideonload.html

Afterwards, the _invalid property value can be changed in the ValueChanged RadTextBox client event handler.

http://www.telerik.com/help/aspnet-ajax/input_clientsideonvaluechanged.html

Greetings,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rafal
Top achievements
Rank 1
answered on 10 May 2011, 03:31 PM
Can this please be added to the back end at some point? it should have been there to begin with....
Thanks
Rafal
0
Tsvetina
Telerik team
answered on 13 May 2011, 09:38 AM
Hello Rafal,

Adding such functionality could introduce a lot of conflicts with custom client-side validation of the controls or validation from other parts of the page . There are many possible scenarios all of which could hardly be handled in order to implement such feature. Currently a scenario requiring not that much custom code does not outweigh the effort and limitations of trying to make this a built-in feature.

Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Input
Asked by
Li Zhou
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Rafal
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or