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

Set a radtextbox to invalid from code behind ?

1 Answer 165 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
guillaume monore
Top achievements
Rank 1
guillaume monore asked on 28 Apr 2011, 10:22 AM
Hello !

   I would like to know if it is possible to set a radtextbox to invalid from code behind ?

   I have a server side validation and i want that my control pass in invalid mode when i come back if it needs.I've tried to set the CssClass to radInvalidCss_Default, but it doesn't seems to work...

    I would like to do as in javascript 
       Mycontrol._invalid = true; 
       Mycontrol.updateCssClass();

thx.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2011, 10:49 AM
Hello,

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(),  Here is a sample code.

aspx:
<telerik:RadTextBox ID="TextBox1" runat="server" ClientEvents-OnLoad="OnLoad">
</telerik:RadTextBox>
<asp:HiddenField ID="h1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Validate" OnClick="Button1_Click" />
C#:
protected void Button1_Click(object sender, EventArgs e)
   {
       h1.Value = "1";
   }

javascript:
<script type="text/javascript">
function OnLoad(sender)
   {
        var h1 = document.getElementById("h1");
        if (h1.value == "1")
        {
            sender._invalid = true;
            sender.updateCssClass()
        }
    }
</script>

Thanks,
Shinu.
Tags
General Discussions
Asked by
guillaume monore
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or