Solved

Validating  custom control

Posted on 2008-06-24
5
801 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

10 Experts available now in Live!

Get 1:1 Help Now