Click here to Skip to main content
15,867,308 members
Articles / Web Development / ASP.NET

Exploring ASP.NET Validators

Rate me:
Please Sign up or sign in to vote.
4.91/5 (41 votes)
9 Apr 2010CPOL19 min read 178.4K   1.8K   123  
This article digs deep into ASP.NET validators and discusses a few case studies which may be a boon for any project
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class caseSStudy2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        string ScriptBlock = "var hdnTextBoxClientId =" + hdnTextBoxIds.ClientID + "; var gridValidatorClientId=" + gridValidator.ClientID +";";
        ScriptManager.RegisterStartupScript(this, this.GetType(),"ClientIds", ScriptBlock, true);
        

        Dictionary<string, string> data = new Dictionary<string, string>();

        data.Add("Item1", "20.4");
        data.Add("Item2", "0");
        data.Add("Item3", "0");
        data.Add("Item4", "12.6");

        rpUpdateAdpdetails.DataSource = data;
        rpUpdateAdpdetails.DataBind();
    }
    protected void rpUpdateAdpdetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        Label lblName = (Label)e.Item.FindControl("lblName");
        Label lblCost = (Label)e.Item.FindControl("lblCost");
        TextBox txtBox = (TextBox)e.Item.FindControl("txtCost");
        lblCost.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
        lblCost.Attributes.Add("onclick", "javascript:openpopup('" + lblCost.ClientID + "','" + txtBox.ClientID + "');");
        hdnTextBoxIds.Value = hdnTextBoxIds.Value + txtBox.ClientID + ",";
        KeyValuePair<string, string> data = (KeyValuePair<string, string>)e.Item.DataItem;
        lblName.Text = data.Key;
        txtBox.Text = data.Value;
        lblCost.Text = data.Value;
        txtBox.Attributes.Add("onfocus", "AttachValidator(this,'" + gridValidator.ClientID + "')");
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.

He is a very passionate .NET developer and have expertise over Web technologies like ASP.NET 2.0/3.5/4.0, jQuery, JSON, Javascript, IIS and related technologies. He is also a Exchange Server (EWS) Specialist. He has great experience in design patterns and N-Tier Architecture.

He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.

He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.

Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.


Visit his Blog: Code Wala

Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008

Comments and Discussions