Hello,
I'm having an issue with the input validations available in the RadInputManager where I need to prevent the user from entering data in other form fields when there is an error in a particular form input field due to the nature of the application. I have code that will disable the input controls, but I cannot find a way to determine is control X is valid.
What I really need is a client side method to determine if the input field is valid or not in my scenario, but cannot seem to find a way to accomplish that using the OnValidating event. In my scenario, I need to dynamically add input validation settings via the page's codebehind (e.g. not through clientside script) and cannot allow the user to add data to other fields while one field is invalid.
In the code below if the line RegExSetting.ClientEvents.OnValidating = "OnClientValidating" is commented out then the user can enter values in any textbox or input field, which is not desired while Textbox1 has an invalid value.
If there was a way to tell if Control X was valid when the control loses focus that would solve the problem (in my actual scenario 100% of the controls are dynamic so I cannot hardcode control names) as I could execute code that re-enables all the controls if Control X is valid.
ASPX:
Code-Behind (VB.NET)
I'm having an issue with the input validations available in the RadInputManager where I need to prevent the user from entering data in other form fields when there is an error in a particular form input field due to the nature of the application. I have code that will disable the input controls, but I cannot find a way to determine is control X is valid.
What I really need is a client side method to determine if the input field is valid or not in my scenario, but cannot seem to find a way to accomplish that using the OnValidating event. In my scenario, I need to dynamically add input validation settings via the page's codebehind (e.g. not through clientside script) and cannot allow the user to add data to other fields while one field is invalid.
- User enters invalid text in TextBox1
- Validation message appears
- All other input controls other than Textbox1 should be disabled
- When the user enters a valid value in Textbox1 that passes the validation then all the other input boxes should be re-enabled (Note: This is the step I cannot determine how to accomplish)
In the code below if the line RegExSetting.ClientEvents.OnValidating = "OnClientValidating" is commented out then the user can enter values in any textbox or input field, which is not desired while Textbox1 has an invalid value.
If there was a way to tell if Control X was valid when the control loses focus that would solve the problem (in my actual scenario 100% of the controls are dynamic so I cannot hardcode control names) as I could execute code that re-enables all the controls if Control X is valid.
ASPX:
<telerik:RadAjaxManager ID="AjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="Area"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="Area" LoadingPanelID="RadAjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="RadInputManager1" /> <telerik:AjaxUpdatedControl ControlID="Button1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadInputManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="Area" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" MinDisplayTime="2000"> </telerik:RadAjaxLoadingPanel> <telerik:RadCodeBlock ID="CodeBlock" runat="server"> <script type="text/javascript" language="javascript"> function OnClientValidating(sender, args) { var inputId = args.get_input().get_id(); if (inputId != null) { var inputs = document.getElementsByTagName('input'); for (element in inputs) { inputs[element].disabled = true; } document.getElementById(inputId).disabled = false; } } function OnClientBlur(sender, args) { //How do I tell if the input is valid, e.g. passed RadInputManager validation setting, OnBlur or another clientside event? } </script></telerik:RadCodeBlock><div> <asp:Panel ID="Area" runat="server"> <asp:PlaceHolder Runat="server" ID="DynamicControls"></asp:PlaceHolder> </asp:Panel> <asp:Button ID="Button1" runat="server" Text="Button" /> </div>Code-Behind (VB.NET)
Private inputManager As New RadInputManager() Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init LoadDynamicControls() LoadDynamicValidation() End Sub Private Sub LoadDynamicControls() Dim txtBox As TextBox = New TextBox() txtBox.ID = "TextBox1" txtBox.AutoPostBack = True txtBox.CausesValidation = True DynamicControls.Controls.Add(txtBox) Dim txtBox2 As TextBox = New TextBox() txtBox2.ID = "TextBox2" txtBox2.AutoPostBack = True txtBox2.CausesValidation = True DynamicControls.Controls.Add(txtBox2) End Sub Private Sub LoadDynamicValidation() Dim RegExPattern As String = "\d{2}/\d{4}" Dim RegExSetting As RegExpTextBoxSetting = New RegExpTextBoxSetting RegExSetting.ValidationExpression = RegExPattern RegExSetting.ErrorMessage = "Test error message" Dim mngr As RadInputManager = inputManager mngr.ID = "RadInputManager1" RegExSetting.TargetControls.Add(New TargetInput("TextBox1", True)) RegExSetting.ClientEvents.OnValidating = "OnClientValidating" mngr.InputSettings.Add(RegExSetting) Page.Form.Controls.Add(mngr) 'RadInputManager1.InputSettings.Add(RegExSetting) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim control As TextBox = FindControl("TextBox1") AjaxManager1.AjaxSettings.AddAjaxSetting(control, control, RadAjaxLoadingPanel1) AjaxManager1.AjaxSettings.AddAjaxSetting(Button1, control, RadAjaxLoadingPanel1) AjaxManager1.AjaxSettings.AddAjaxSetting(inputManager, control, RadAjaxLoadingPanel1) End SubEnd Class