Remove "Required" from Target Control in Input Manager programmatically

2 posts, 0 answers
  1. Kevin
    Kevin avatar
    30 posts
    Member since:
    Sep 2012

    Posted 04 Mar 2010 Link to this post

    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"    
            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()  
    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()  

    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.
  2. Nikolay Rusev
    Nikolay Rusev avatar
    2289 posts

    Posted 09 Mar 2010 Link to this post

    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>
    04.    <asp:Button runat="server" ID="Button2" Text="Validate" ValidationGroup="Group"/>
    06.    <asp:Button runat="server" ID="Button1" Text="Remove First TextBox"
    07. OnClick="Button1_Click"/>    
    09.    <asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
    11.    </form>

    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);
    10.        RadInputManager mng = new RadInputManager();
    11.        mng.ID = "RadInputManager2";
    14.        TextBoxSetting setting = new TextBoxSetting();
    15.        mng.InputSettings.Add(setting);
    17.        setting.Validation.IsRequired = true;
    18.        setting.Validation.ValidationGroup = "Group";
    20.        setting.TargetControls.Add(new TargetInput(t1.ID,true));
    21.        setting.TargetControls.Add(new TargetInput(t2.ID, true));
    23.        PlaceHolder1.Controls.Add(mng);
    24.    }
    26.    protected void Button1_Click(object sender, EventArgs e)
    27.    {
    28.        (FindControl("RadInputManager2") as RadInputManager).InputSettings[0].TargetControls.RemoveAt(0);
    29.         }

    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.
Back to Top