Compare and Confirm Button

G

gover

Hello,
I have a requirement to display a Confirmation pop-up message (' i.e. a
are you sure yes/no) when a user clicks a submit button AND one date field
on my page is less than another date field on my page. I have written the
JavaScript to do this on one page, and am now trying to encapsulate it into a
reusable control. (Source Below) The control is based on a submit button
but also has the functionality of a validator (i.e. control to validate,
control to compare etc. ) The goal is that when the user clicks the button ,
I call the ValidatorCompare JavaScript function and if the condition is not
met, a JavaScript Confirm box is displayed.

I'm having difficulty calling into the WebUIValidation.js function
ValidatorCompare(operand1, operand2, operator, val) . The fourth argument is
JavaScript validator and I don't know how to create one to pass to the
function. I tried this
var val = new Validator();
but I got an error message "Microsoft JScript runtime error: 'Validator' is
undefined".
Can someone tell Me if the fourth argument is in fact a JavaScript
Validator object and where/how to define one?
Russ


CODE
[DefaultProperty("Text")]
[ToolboxData("<{0}:ConfirmButton runat=server Text=\"ConfirmButton\"
Message=\"ConfirmationMessage\"></{0}:ConfirmButtonw>")]
public class ConfirmButton : System.Web.UI.WebControls.Button
{
string message;
#region atteributes

[Bindable(true),Category("Appearance"),DefaultValue(""),Localizable(true)]
public string Message
{
get
{ return message; }
set
{ message = value; }
}
[TypeConverter(typeof(ValidatedControlConverter)),
Category("Behavior"), Themeable(false), DefaultValue(""),
Description("CompareValidator_ControlToValidate")]
public string ControlToValidate
{
get
{
object controlToValidate =
this.ViewState["ControlToValidate"];
if (controlToValidate != null)
{
return (string)controlToValidate;
}
return string.Empty;
}
set
{
this.ViewState["ControlToValidate"] = value;
}
}
[TypeConverter(typeof(ValidatedControlConverter)),
Category("Behavior"), Themeable(false), DefaultValue(""),
Description("CompareValidator_ControlToCompare")]
public string ControlToCompare
{
get
{
object ControlToValidate = this.ViewState["ControlToCompare"];
if (ControlToValidate != null)
{
return (string)ControlToValidate;
}
return string.Empty;
}
set
{
this.ViewState["ControlToCompare"] = value;
}
}
[Category("Behavior"), Themeable(false), DefaultValue(""),
Description("CompareValidator_ValueToCompare")]
public string ValueToCompare
{
get
{
object ValueToCompare = this.ViewState["ValueToCompare"];
if (ValueToCompare != null)
{
return (string)ValueToCompare;
}
return string.Empty;
}
set
{
this.ViewState["ValueToCompare"] = value;
}
}



[DefaultValue(0), Themeable(false), Category("Behavior"),
Description("CompareValidator_Operator")]
public ValidationCompareOperator Operator
{
get
{
object Operator = this.ViewState["Operator"];
if (Operator != null)
{
return (ValidationCompareOperator)Operator;
}
return ValidationCompareOperator.Equal;
}
set
{
if ((value < ValidationCompareOperator.Equal) || (value >
ValidationCompareOperator.DataTypeCheck))
{
throw new ArgumentOutOfRangeException("value");
}
this.ViewState["Operator"] = value;
}
}
#endregion attributes
protected string GetControlRenderID(string name)
{
Control control = this.FindControl(name);
if (control == null)
{
return string.Empty;
}
return control.ClientID;
}
protected override void OnPreRender(EventArgs e)
{

string ControlToCompareClientID =
GetControlRenderID(this.ControlToCompare);
message += GetControlRenderID(this.ControlToCompare);
message += GetControlRenderID(this.ControlToCompare);
string vbCrLf = "\n\r";
Page.RegisterClientScriptBlock("__doAlert",
"<script language=\"javascript\">" + vbCrLf +
"function __doConfirm(btn){" + vbCrLf +
// lots of test stuff here, need to call WEBUI Validation to compare
"var valuetocompare;" + vbCrLf +
// this gets the value as a string
"valuetocompare=ValidatorGetValueRecursive(" + ControlToCompareClientID +
");" + vbCrLf +
// need to get value as an object by calling ValidatorConvert, but to do
this I need a javascript 'val'
//How do I create the second parm
"alert( ValidatorConvert(valuetocompare,\"Date\",null));" + vbCrLf +

"var answer = confirm(\"" + message + "\");" + vbCrLf +
"if (answer){" + vbCrLf +
"return true;}" + vbCrLf +
"else{" + vbCrLf +
"return false;}}" + vbCrLf +
"</script>"
);

this.Attributes["onclick"] = "return __doConfirm(this);";

base.OnPreRender(e);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top