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

Remove "Required" from Target Control in Input Manager programmatically

1 Answer 113 Views
Input
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 04 Mar 2010, 05:16 PM
In the "How to Add" version of this thread the following block of code was posted:
        Dim InputMgr As RadInputManager = New RadInputManager    
        InputMgr.ID = "RadInputManager1"    
        InputMgr.Skin = "Vista"    
            
        Dim DateSetting As DateInputSetting = New DateInputSetting    
        DateSetting.MinDate = New DateTime(1980, 1, 1)    
        DateSetting.MaxDate = New DateTime(2020, 1, 1)    
        DateSetting.ClientEvents.OnError = "onClientDateTxtError"    
        DateSetting.ClientEvents.OnKeyPress = "onClientTextChanged"    
        InputMgr.InputSettings.Add(DateSetting)    
            
        TryCast(InputMgr.InputSettings(0), InputSetting).TargetControls.Add(New TargetInput(TextBox1.UniqueID, True))    
            
 

What I have a is form full of fields and a dropdown list.  By default a certain set of fields are handled through the input manager through the Regular Expression Text Box setting, as well as being set as required.  When certain options are selected in the dropdown list, different sets of fields are required.

So what I'd like to do is if Social Security number is no longer required I'd like to set the SSN Behavior to no longer be required, or if that doesn't work, then I'd like to remove the control txtSSN from the target control list for that Input setting.

In trying to make the input no longer required I tried this:
Dim a As String = RadInputManager1.InputSettings(0).TargetControls.Item(0).ControlID.ToString()  
 
Stop  
 
RadInputManager1.InputSettings(0).Validation.IsRequired = False 

At the stop point I verify that variable a holds the correct control name, which it does, but the final line seems to do nothing.  The control still appears to be required.

In trying to remove the control from the Input Manager behavior all together I tried the following:
Dim a As String = RadInputManager1.InputSettings(0).TargetControls.Item(0).ControlID.ToString()  
 
Stop  
 
RadInputManager1.InputSettings(0).TargetControls.RemoveAt(0) 

At the stop point I verify that variable a has the correct control name, which it does.  Then I would think the final line would remove that control from the Input Manager, but if I go to that control after this executes the field is still required and the regular expression still restricts my input into that field.

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 09 Mar 2010, 10:39 AM
Hello Kevin,

I have just tried programmatically add RadInputManager and on button click to remove first TextBox from the settings and all seems to be working just fine.

Bellow is my code:
/aspx markup/
01.<form id="form1" runat="server">
02.    <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
03.      
04.    <asp:Button runat="server" ID="Button2" Text="Validate" ValidationGroup="Group"/>
05.      
06.    <asp:Button runat="server" ID="Button1" Text="Remove First TextBox"
07. OnClick="Button1_Click"/>    
08.      
09.    <asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
10.      
11.    </form>

/code-behind/
01.protected void Page_Load(object sender, EventArgs e)
02.    {
03.        TextBox t1 = new TextBox();
04.        t1.ID = "T1";
05.        PlaceHolder1.Controls.Add(t1);
06.        TextBox t2 = new TextBox();
07.        t2.ID = "T2";
08.        PlaceHolder1.Controls.Add(t2);
09.  
10.        RadInputManager mng = new RadInputManager();
11.        mng.ID = "RadInputManager2";
12.         
13.  
14.        TextBoxSetting setting = new TextBoxSetting();
15.        mng.InputSettings.Add(setting);
16.  
17.        setting.Validation.IsRequired = true;
18.        setting.Validation.ValidationGroup = "Group";
19.  
20.        setting.TargetControls.Add(new TargetInput(t1.ID,true));
21.        setting.TargetControls.Add(new TargetInput(t2.ID, true));
22.  
23.        PlaceHolder1.Controls.Add(mng);
24.    }
25.  
26.    protected void Button1_Click(object sender, EventArgs e)
27.    {
28.        (FindControl("RadInputManager2") as RadInputManager).InputSettings[0].TargetControls.RemoveAt(0);
29.         }


Greetings,
Nikolay
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.
Tags
Input
Asked by
Kevin
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or