Dropdowntree in usercontrol

6 posts, 1 answers
  1. Prabha
    Prabha avatar
    26 posts
    Member since:
    Dec 2013

    Posted 10 Jun 2014 Link to this post

    hai all,
                Im having a user control (.ascx) with a rad dropdowntree. when im truing to use that usercontrol on my aspx, i have to validate that dropdowntree (ie. it is a mandatory field in my .aspx).im unable to use "RequiredFieldValidator" on user control.Is there any control available in Telerik like RequiredFieldValidator. If available, how to use that rad validation  control on Usercontrol?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2014 in reply to Prabha Link to this post

    Hi Prabha,

    Please have a look into the sample code snippet to achieve your scenario.

    ASCX:
    <telerik:RadDropDownTree ID="RadDropDownTree1" runat="server" DataTextField="text"
        DataFieldID="id" DataFieldParentID="parentid" DataSourceID="SqlDataSource1">
    </telerik:RadDropDownTree>

    ASCX.CS
    [ValidationProperty("Text")]
    public partial class RadDropDownTree_DropTree : System.Web.UI.UserControl
    {
         public string Text
         {
             get { return RadDropDownTree1.SelectedText; }
     
         }
    }

    ASPX:
    <uc1:DropTree ID="DropTree1" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="This is a required field." ControlToValidate="DropTree1">
    </asp:RequiredFieldValidator>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

    ASPX.CS:
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Prabha
    Prabha avatar
    26 posts
    Member since:
    Dec 2013

    Posted 10 Jun 2014 in reply to Shinu Link to this post

    hi Shinu,
         I have tried the thing which you provide. but if i will use
                     Page.Validate();
                    if (Page.IsValid)
                    {
                           //my insert code
                      }
    it wont go inside the if statement event i have provide all my input. And also, if i dont select any item in dropdownbox also, it wont show any validation messages. May i know what is the use of "Page.IsValid" method.
  5. Prabha
    Prabha avatar
    26 posts
    Member since:
    Dec 2013

    Posted 10 Jun 2014 in reply to Shinu Link to this post

    hi shinu,
        sorry for my previous reply. your sample snippet is working fine. But what exactly i need is , in my page there are more than one controls except usercontrol. All controls having their own "RequiredFieldValidator". And finally i shows the  "ValidationSummary" with all validation message. If i will use your code means, except my usercontrol validation, other validation will come first. When the button click event call only the user control validation occur. But i have to validate all the controls at a time and summarize it. 
  6. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Jun 2014 in reply to Prabha Link to this post

    Hi Prabha,

    Please have  a look into the following code snippet which works fine at my end and take a look into the attached screenshots.

    ASPX:
    <asp:TextBox ID="TextBox1" runat="server">
    </asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="Group1"
        runat="server" Display="None" ErrorMessage="TextBox is a required dield." ControlToValidate="TextBox1">
    </asp:RequiredFieldValidator>
    <uc1:DropTree ID="DropTree1" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="Group1"
        runat="server" Display="None" ErrorMessage="DropDown is a required field." ControlToValidate="DropTree1">
    </asp:RequiredFieldValidator>
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Group1"
        DisplayMode="BulletList" ShowMessageBox="true" HeaderText="Please notice that:" />
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

    Thanks,
    Shinu.
  7. Prabha
    Prabha avatar
    26 posts
    Member since:
    Dec 2013

    Posted 11 Jun 2014 in reply to Shinu Link to this post

    hi shinu,
          Its working fine.

    Thank you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017