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

Dropdowntree in usercontrol

5 Answers 20 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Prabha
Top achievements
Rank 1
Prabha asked on 10 Jun 2014, 06:31 AM
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?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 10 Jun 2014, 12:28 PM
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.
0
Prabha
Top achievements
Rank 1
answered on 10 Jun 2014, 12:58 PM
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.
0
Prabha
Top achievements
Rank 1
answered on 10 Jun 2014, 01:06 PM
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. 
0
Accepted
Shinu
Top achievements
Rank 1
answered on 11 Jun 2014, 11:30 AM
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.
0
Prabha
Top achievements
Rank 1
answered on 11 Jun 2014, 11:37 AM
hi shinu,
      Its working fine.

Thank you.
Tags
DropDownTree
Asked by
Prabha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Prabha
Top achievements
Rank 1
Share this question
or