-/**
- * Namespace: System.Web.UI.WebControls
- * Class: BaseValidator
- *
- * Authors: Gaurav Vaish, Gonzalo Paniagua Javier
- * Maintainer: gvaish@iitk.ac.in
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>, <gonzalo@ximian.com>
- * Implementation: yes
- * Status: 80%
- *
- * (C) Gaurav Vaish (2001)
- * (c) 2002 Ximian, Inc. (http://www.ximian.com)
- */
+//
+// System.Web.UI.WebControls.BaseValidator.cs
+//
+// Authors:
+// Gaurav Vaish (gvaish@iitk.ac.in)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (c) 2002 Ximian, Inc. (http://www.ximian.com)
+// (C) Gaurav Vaish (2002)
+// (C) 2003 Andreas Nahr
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;
using System.ComponentModel;
+using System.ComponentModel.Design;
using System.Web;
using System.Web.UI;
using System.Drawing;
namespace System.Web.UI.WebControls
{
[DefaultProperty("ErrorMessage")]
- //TODO: [Designer("??")]
+ [Designer ("System.Web.UI.Design.WebControls.BaseValidatorDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
public abstract class BaseValidator: Label, IValidator
{
private bool isValid;
renderUplevel = false;
}
+ [DefaultValue (""), WebCategory ("Behavior")]
+ [TypeConverter (typeof (ValidatedControlConverter))]
+ [WebSysDescription ("The ID of the control to validate.")]
public string ControlToValidate
{
get
}
}
+ [DefaultValue (typeof (ValidatorDisplay), "Static"), Bindable (true), WebCategory ("Appearance")]
+ [WebSysDescription ("Determines how the validator is displayed.")]
public ValidatorDisplay Display
{
get
{
throw new ArgumentException();
}
- ViewState["ValidatorDisplay"] = value;
+ ViewState["Display"] = value;
}
}
+ [DefaultValue (true), WebCategory ("Behavior")]
+ [WebSysDescription ("Determines if client script is activated on uplevel browsers.")]
public bool EnableClientScript
{
get
}
}
+ [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
+ [WebSysDescription ("An error message that is displayed if the control validates to false.")]
public string ErrorMessage
{
get
}
}
+ [DefaultValue (null)]
public override Color ForeColor
{
get
}
}
+ [DefaultValue (true), Browsable (false), WebCategory ("Misc")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [WebSysDescription ("Indicates if the control validated to false.")]
public bool IsValid
{
get { return isValid; }
if(!Visible || (Visible && !Enabled))
{
IsValid = true;
+ return;
}
+
Control ctrl = Parent;
while(ctrl != null)
{
if(enabled)
{
- Enabled = false;
+ base.Enabled = false;
}
}
return true;
}
- [MonoTODO]
protected virtual bool DetermineRenderUplevel()
{
Page page = Page;
if(EnableClientScript)
{
- // By now, return false
- //return false;
- throw new NotImplementedException();
- ////TODO: I need to get the (Browser->Dom_version_major >= 4 &&
- //// Brower->Ecma_script_version >= 1.2)
+ if(page.Request.Browser.MSDomVersion.Major > 4)
+ {
+ return page.Request.Browser.EcmaScriptVersion.CompareTo(new Version(1,2)) >= 0;
+ }
+ return false;
}
return false;
}
PropertyDescriptor pd = GetValidationProperty(ctrl);
if(pd != null)
{
- object item = pd.GetValue(ctrl);
- if(item is ListItem)
- {
- return ((ListItem)item).Value;
- }
- return item.ToString();
+ object item = pd.GetValue (ctrl);
+ if (item is ListItem)
+ return ((ListItem) item).Value;
+
+ if (item == null)
+ return String.Empty;
+
+ return item.ToString ();
}
}
return null;
base.OnUnload(e);
}
- [MonoTODO("What_do_I_have_to_do")]
+ [MonoTODO("Damn_This_Is_Really_Frustrating___by_Gaurav")]
protected void RegisterValidatorCommonScript()
{
- // Keep going
- //throw new NotImplementedException();
+ if(Page.ClientScript.IsClientScriptBlockRegistered("ValidatorIncludeScript"))
+ return;
+
+ //string jsDirectory = System.Web.UI.Utils.GetScriptLocation(Context);
+ //string jsFile = jsDirectory + "/WebUIValidation.js";\r
+
+ //TODO: Ok, now add the <script language="javascript"> etc
+ //FIXME: Should I check for 'Explorer'? MS-Net seems to do it!
+ throw new NotImplementedException();
}
[MonoTODO("I_have_to_know_javascript_for_this_I_know_it_but_for_ALL_browsers_NO")]
protected virtual void RegisterValidatorDeclaration()
{
- throw new NotImplementedException();
- //TODO: Since I have to access document.<ClientID> and register
- // as page validator. Now this is Browser dependent :((
-
- // This does not render anything on Mozilla, and does on IE
+ //FIXME: How to make is more abstract?
+ //Browser Info... but future browsers???
+ //I'm confused! This will make it work, at least on IE
+ string val = "document.all[\"" + ClientID;
+ val += "\"]";
+ Page.ClientScript.RegisterArrayDeclaration("Page_Validators", val);
}
[MonoTODO("Render_ing_always_left")]
ValidatorDisplay dis = Display;
if (RenderUplevel) {
- //FIXME: by now, don't do client-side validation
+ //FIXME: as of now, don't do client-side validation
+ throw new NotImplementedException();
}
-
- if (!valid) {
+
+ if (!valid && dis != ValidatorDisplay.None) {
RenderBeginTag (writer);
- if (Text.Trim ().Length > 0 || HasControls ()) {
+ if (Text.Trim ().Length > 0 || HasControls ())
RenderContents (writer);
- RenderEndTag (writer);
- } else {
+ else
writer.Write (ErrorMessage);
- }
RenderEndTag (writer);
return;
}
protected abstract bool EvaluateIsValid();
}
}
-