Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Compare and Confirm Button

Reply
Thread Tools

Compare and Confirm Button

 
 
gover
Guest
Posts: n/a
 
      07-02-2007
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);

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to handle Cancel button in Confirm() method? lakshmikandhan@gmail.com ASP .Net 3 04-04-2006 10:51 AM
pop-up with yes-no button instead of confirm() with ok-cancel button Indu Javascript 9 11-20-2005 02:46 PM
How to show a confirm box with Button Click ad ASP .Net 3 09-23-2005 10:21 PM
Problem showing confirm dialog on button webcontrol's onclick even =?Utf-8?B?VGFydW4gVXBhZGh5YXlh?= ASP .Net 3 06-02-2005 04:19 PM
do JS 'Confirm' for Button web control Paul W ASP .Net 3 11-15-2004 06:53 PM



Advertisments