473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Custom Validator Control

Can I create a custom validator control in my project and add it to a
PlaceHolder on my ASPX page??

Here is what I've tried. It compiles and runs without error, but doesn't
detected that the checkbox it is validating is checked when the form is
submitted.

TIA,
George

------------------ from target ASPX page ----------------------------------
.....
<asp:placeholder id="TermsAndConditionsCv" Runat="server"></asp:placeholder>
.....
------------------- from target ASPX.CS
page --------------------------------
protected override void OnPreRender(EventArgs e)

{

Components.CheckBoxValidator checkBoxValidator = new
MobileGuardianWeb.Components.CheckBoxValidator();

checkBoxValidator.ControlToValidate = TermsAndConditions.ID;

checkBoxValidator.ErrorMessage = "You must agree to our terms and
condtions";

checkBoxValidator.Text = "*";

checkBoxValidator.ForeColor = System.Drawing.Color.Red;

checkBoxValidator.Display = ValidatorDisplay.Dynamic;

TermsAndConditionsCv.Controls.Add(checkBoxValidato r);

base.OnPreRender (e);

}

------------------- source for validator:
Components/CheckBoxValidator.cs --------------------------------------
using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

namespace MyProject.Components

{

/// <summary>

/// Summary description for CheckBoxValidator.

/// </summary>

public class CheckBoxValidator: BaseValidator

{

private CheckBox _checkbox = null;

public CheckBoxValidator()

{

base.EnableClientScript = true;

}

protected override bool ControlPropertiesValid()

{

Control ctrl = FindControl(ControlToValidate);
if (ctrl != null)

{

_checkbox = (CheckBox) ctrl;

return (_checkbox != null);

}

else

return false; // raise exception

}

protected override bool EvaluateIsValid()

{

return _checkbox.Checked;

}

}

}
Nov 18 '05 #1
1 1964
Are you trying to stop submission client side? You will need to output some
javascript to work client side.

Also the control isn't being added to the page until PreRender which is way
after any event processing, so you will miss out on that server side.

HTH,
bill
"DotNetGruven" <ms********@javagruven.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Can I create a custom validator control in my project and add it to a
PlaceHolder on my ASPX page??

Here is what I've tried. It compiles and runs without error, but doesn't
detected that the checkbox it is validating is checked when the form is
submitted.

TIA,
George

------------------ from target ASPX page ---------------------------------- ....
<asp:placeholder id="TermsAndConditionsCv" Runat="server"></asp:placeholder> ....
------------------- from target ASPX.CS
page --------------------------------
protected override void OnPreRender(EventArgs e)

{

Components.CheckBoxValidator checkBoxValidator = new
MobileGuardianWeb.Components.CheckBoxValidator();

checkBoxValidator.ControlToValidate = TermsAndConditions.ID;

checkBoxValidator.ErrorMessage = "You must agree to our terms and
condtions";

checkBoxValidator.Text = "*";

checkBoxValidator.ForeColor = System.Drawing.Color.Red;

checkBoxValidator.Display = ValidatorDisplay.Dynamic;

TermsAndConditionsCv.Controls.Add(checkBoxValidato r);

base.OnPreRender (e);

}

------------------- source for validator:
Components/CheckBoxValidator.cs --------------------------------------
using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

namespace MyProject.Components

{

/// <summary>

/// Summary description for CheckBoxValidator.

/// </summary>

public class CheckBoxValidator: BaseValidator

{

private CheckBox _checkbox = null;

public CheckBoxValidator()

{

base.EnableClientScript = true;

}

protected override bool ControlPropertiesValid()

{

Control ctrl = FindControl(ControlToValidate);
if (ctrl != null)

{

_checkbox = (CheckBox) ctrl;

return (_checkbox != null);

}

else

return false; // raise exception

}

protected override bool EvaluateIsValid()

{

return _checkbox.Checked;

}

}

}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
1
by: Vinod I | last post by:
Hi Team, I made a custom validator control which is having 2 public properties. But after making dll & adding that to the ToolBox, I could not able to find these properties in Property Box. ...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
1
by: Jim Heavey | last post by:
Can I create a generic Javascrip custom validator in which I can pass multiple parameters? Looking at examples, it does not appear that I can. I want to create a custom validator which will look...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
2
by: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
0
by: Marek | last post by:
Hi all, I have custrom control with four elements: text box, regular expression validator, required field validator and custom validator. Next this control is dragged on to web site with several...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
0
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
4
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.