Solved

Validating  custom control

Posted on 2008-06-24
5
798 Views
Last Modified: 2012-08-14
Hi,
1) I am developing a custom control containing textboxes. I want to use required field, reg expression and compare validation controls to check  custom control's textbox inputs.
2)Also when i will use custom control in .aspx web page. It will use validation summary control of the .aspx web page to display validation error message.
Please help me out in this case    
Cheers
0
Comment
Question by:Manusmrati
  • 2
5 Comments
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 21854190
Hi

try this. go thru ValidationProperty("Text")]


using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


[DefaultProperty("Text"), ToolboxData("<{0}:Textvalidator runat=server></{0}:Textvalidator>"), ValidationProperty("Text")]
public class Textvalidator : WebControl, INamingContainer
{
   
    TextBox t;
    Button b;
    protected override void OnInit(EventArgs e)
    {
        t = new TextBox();
        b = new Button();
        this.Controls.Add(t);
        this.Controls.Add(b);
    }
   
    [Bindable(true), Category("Appearance"), DefaultValue(""), Localizable(true)]
    public string Text {

        get { return t.Text; }
       
        set { t.Text = value; }
    }
   
}
0
 

Author Comment

by:Manusmrati
ID: 21854398
Hi

Thanks for your reply, Actually Its a Common fields Address custom control with textboxes and labels. I have a provision to diable textboxes and lable at run time, So you can custamize it according to your need.Till that time, i am rendering the textboxes using override render method. I am not creating an instance of the textbox which you used in your above mentioned code. Is there a way i can add client side validation using embedded javascript file.  I think if you rendering a control , client side validation is the best solution.
Or
I would go for creating a instance of the texboxes and label and individually go for ValidationPropertyAttribute check .
Suggestions are welcomed.
Cheers

need your view point.
Cheers
0
 
LVL 12

Accepted Solution

by:
madhevan_pillai earned 250 total points
ID: 21855424
Instance method is the best one. You can directly bind  the custom control to validation controls.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now