473,398 Members | 2,165 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,398 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 1966
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.