D
Dhanashree
I have a RangeValidator which uses AJAX to call server-side validation
function from the client. The code works fine, but I have one problem.
following is my range validator class:
public class RangeValidator: BaseValidator,ICallbackEventHandler
{
public event ServerValidateEventHandler ServerValidate;
String _controlToValidateValue;
protected override void OnPreRender(EventArgs e)
{
String eventRef =
Page.ClientScript.GetCallbackEventReference(this, "", "", "");
// Register include file
String includeScript = Page.ResolveClientUrl("~/
ClientScripts/AjaxValidator.js");
Page.ClientScript.RegisterClientScriptInclude("MyAjaxValidator",
includeScript);
// Register startup script
String startupScript =
String.Format("document.getElementById('{0}').evaluationfunction =
'AjaxValidatorEvaluateIsValid';", this.ClientID);
Page.ClientScript.RegisterStartupScript(this.GetType(),
this.ClientID, startupScript);
base.OnPreRender(e);
}
.....
}
This is how I use it in the aspx file
<cc1:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="Test1"
Display="Dynamic" OnServerValidate="test1_servervalidate"></
cc1:RangeValidator>
<cc1:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="Test2"
Display="Dynamic" OnServerValidate="test2_servervalidate"></
cc1:RangeValidator>
So the onPreRender is called twice when this page loads. The code
compiles and the validation works fine, but only for the first "Test1"
control only. And it doesnt fire the validation events for the second
one.
Here is how it is rendered:
<script type="text/javascript">
<!--
WebForm_InitCallback();document.getElementById('RangeValidator1').evaluationfunction
= 'AjaxValidatorEvaluateIsValid';// -->
</script>
<script type="text/javascript">
<!--
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
// -->
</script>
<script type="text/javascript">
<!--
document.getElementById('RangeValidator2').evaluationfunction =
'AjaxValidatorEvaluateIsValid';// -->
</script>
Any idea on why this is not working for the second validator? Thanks
in advance.
function from the client. The code works fine, but I have one problem.
following is my range validator class:
public class RangeValidator: BaseValidator,ICallbackEventHandler
{
public event ServerValidateEventHandler ServerValidate;
String _controlToValidateValue;
protected override void OnPreRender(EventArgs e)
{
String eventRef =
Page.ClientScript.GetCallbackEventReference(this, "", "", "");
// Register include file
String includeScript = Page.ResolveClientUrl("~/
ClientScripts/AjaxValidator.js");
Page.ClientScript.RegisterClientScriptInclude("MyAjaxValidator",
includeScript);
// Register startup script
String startupScript =
String.Format("document.getElementById('{0}').evaluationfunction =
'AjaxValidatorEvaluateIsValid';", this.ClientID);
Page.ClientScript.RegisterStartupScript(this.GetType(),
this.ClientID, startupScript);
base.OnPreRender(e);
}
.....
}
This is how I use it in the aspx file
<cc1:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="Test1"
Display="Dynamic" OnServerValidate="test1_servervalidate"></
cc1:RangeValidator>
<cc1:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="Test2"
Display="Dynamic" OnServerValidate="test2_servervalidate"></
cc1:RangeValidator>
So the onPreRender is called twice when this page loads. The code
compiles and the validation works fine, but only for the first "Test1"
control only. And it doesnt fire the validation events for the second
one.
Here is how it is rendered:
<script type="text/javascript">
<!--
WebForm_InitCallback();document.getElementById('RangeValidator1').evaluationfunction
= 'AjaxValidatorEvaluateIsValid';// -->
</script>
<script type="text/javascript">
<!--
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
// -->
</script>
<script type="text/javascript">
<!--
document.getElementById('RangeValidator2').evaluationfunction =
'AjaxValidatorEvaluateIsValid';// -->
</script>
Any idea on why this is not working for the second validator? Thanks
in advance.