Solved

Validating  custom control

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 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