locked
How to set the initial value of radDropDownList in requiredfieldvalidator RRS feed

  • Question

  • User355715116 posted

    I have a dropdownlist 


    <td>
      <telerik:RadDropDownList ID="stateComboBox" runat="server" DataTextField="SateCode" DataValueField="SateCode" Width="173px">
      </telerik:RadDropDownList>
    </td>

    I want to set the requiredfieldvalidator for the dropdownlist (stateComboBox)

    <td>
      <asp:RequiredFieldValidator ID="rvfState" runat="server" ControlToValidate="stateComboBox"
    ErrorMessage="State is Required" ForeColor="#CC0000">*</asp:RequiredFieldValidator></td>

    Now my question is how can i set initial value for stateComboBox in my RequiredFieldValidator.

    Thanks in advance 

    Wednesday, June 3, 2020 12:40 PM

All replies

  • User409696431 posted

    Your question is confusing.  The title says you want to set the initial value of a RadDropDownList in a RequiredFieldValidator.

    Then you say, in the body of the post, "I want to set the requiredfieldvalidator for the dropdownlist (stateComboBox)".  A ComboBox is not a RadDropDownList, and I'm not sure what you mean by "stateComboBox".

    Can you clarify what you really asking?

    I'll point out that you don't set an initial value with a RequiredFieldValidator.  You can tell the RequiredFieldValidator what the initial value of the control is, and it will fire its error message if the user doesn't change that initial value.

    See https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.requiredfieldvalidator.initialvalue?view=netframework-4.8#System_Web_UI_WebControls_RequiredFieldValidator_InitialValue

    Wednesday, June 3, 2020 1:28 PM
  • User355715116 posted

    Hello KathyW,

    As you can see i am not using combobox here. I am using RadDropDownlIast here just the name is stateCombopBox. 

    Actually i wanted to add required filed validator fop my  RadDropDownlIast(Id: stateComboBox) and there is a property called initialValue. 
    So i just wanted to know that how can i set the initial value for RadDropDownlIast(Id: stateComboBox) in respective required field validator. 

    Do you got my point now? 

     

    Wednesday, June 3, 2020 1:39 PM
  • User355715116 posted

    Thanks for your concern but as you can see in my code there is no list item inside my radDropDown list , so how can  i set initial value in requiredfieldvalidator ?

    Wednesday, June 3, 2020 1:43 PM
  • User475983607 posted

    mazharul007

    Thanks for your concern but as you can see in my code there is no list item inside my radDropDown list , so how can  i set initial value in requiredfieldvalidator ?

    It helps if you explain the problem you are trying to solve rather than the solution. 

    The reference documentation covers how the RequiredFieldValidator.InitialValue Property works.  The documentation also has sample code that shows how the value is set.  https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.requiredfieldvalidator.initialvalue?view=netframework-4.8

    The default initial value is "empty".  Lets say your dropdown does not have an empty option rather it has 0.  Then you would set RequiredFieldValidator.InitialValue to 0.  If the user does not make a selection other than 0 then the validation will fire.  Please read the link, it has everything you need.

    Wednesday, June 3, 2020 2:02 PM
  • User409696431 posted

    "there is no list item inside my radDropDown list , so how can i set initial value in requiredfieldvalidator ?"

    Well, I assume you will be populating that somehow.  Only you know what the initial value will be.

    Wednesday, June 3, 2020 2:37 PM
  • User-939850651 posted

    Hi, mazharul007

    I found that attributes of RadCombox items is similar to DropDownList.

    I think  the second answer of this case may be useful for you. You could try it.

    And how to add items programmatically, you could refer this document.

    Hope this can help you.

    Best regards,

    Xudong Peng

    Thursday, June 4, 2020 10:08 AM