Title

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help
in Search

Eralper's Blog on Software Development



MaskedEditValidator control NullReferenceException at TextBox Target = (TextBox)MaskExt.FindControl(ControlToValidate);

Hi,

If you are playing around with the AjaxControlToolkit controls and extenders, you might have experienced the following NullReferenceException error with the MaskedEditValidator Ajax control extender:


{"Object reference not set to an instance of an object."}

or in detail;


System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="AjaxControlToolkit"
StackTrace:
at AjaxControlToolkit.MaskedEditValidator.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:


Actually, the problem or the error occurs when the ControlExtender property of the MaskedEditValidator control is left unset to the related MaskedEditExtender control Id.

Here is a sample which causes the build error above:


<cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server"
ControlToValidate="TextBox2" Display="Dynamic" EmptyValueBlurredText="*"
EmptyValueMessage="Date is required" InvalidValueBlurredMessage="*"
InvalidValueMessage="Date is invalid" ToolTip="Input a date"
ValidationGroup="MKE"></cc1:MaskedEditValidator>

And if you add the

ControlExtender="TextBox2_MaskedEditExtender"


in order to complete the settings for the MaskedEditValidator


<cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server"
ControlToValidate="TextBox2" Display="Dynamic" EmptyValueBlurredText="Empty Date"
EmptyValueMessage="Date is required" InvalidValueBlurredMessage="Invalid Date"
InvalidValueMessage="Date is invalid" ToolTip="Input a date"
ValidationGroup="MKE"
ControlExtender="TextBox2_MaskedEditExtender"></cc1:MaskedEditValidator>


Then the problem is solved.

I have made this mistake to set the ControlExtender property. So that is a simple solution :)


Technorati Profile | Add to Technorati Favorites

Published Thursday, December 13, 2007 11:23 AM by eralper
Filed Under: ,

Comments

No Comments
Anonymous comments are disabled
Copyright © 2004 - 2008 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems