I have install and setup the Asp.net version of AjaxControlToolkit.
version 4.1.5
.Net 4.0
VS 2010
I’m trying to uses the AjaxControlToolkit.MaskedEditExtender Ajax control.
I have setup up a DetailView and some custom Templates that will allow me access to the TextBoxs.
But keep getting this error :
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
>
> Source Error:
>
> An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location
> of the exception can be identified using the exception stack trace
> below.
>
> Stack Trace:
>
> [NullReferenceException: Object reference not set to an instance of an object.]
> AjaxControlToolkit.MaskedEditExtender.OnLoad(EventArgs e) in
> C:\Users\Stephen\Documents\Repos\Superexpert\AjaxControlToolkit\Server\AjaxControlToolkit\MaskedEdit\MaskedEditExtender.cs:95
> System.Web.UI.Control.LoadRecursive() +74
> System.Web.UI.Control.LoadRecursive() +146
> System.Web.UI.Control.LoadRecursive() +146
> System.Web.UI.Control.LoadRecursive() +146
> System.Web.UI.Control.LoadRecursive() +146
> System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> +2207
Here is my code for that section(HTML page .ASPX)
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="New.aspx.cs" Inherits="AequorPubTracker.Account.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
Search:
<asp:TextBox ID="SearchTextBox" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" />
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="LinqDataSource1"
Height="50px" onpageindexchanging="DetailsView1_PageIndexChanging"
style="margin-top: 20px" Width="472px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# BIND("PubId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# BIND("PubID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("PubId") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Sent_from_naylor") %>'></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text='<%# Eval("RecByAequorMgt") %>'></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text='<%# Eval("AssignedToAequorRes") %>'></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text='<%# Eval("SentTonaylor") %>'></asp:Label>
<br />
<asp:Label ID="Label7" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
TargetControlID="TextBox1"
Mask="999,9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="Left"
DisplayMoney="Left"
ErrorTooltipEnabled="True"/>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" runat="server"
TargetControlID="TextBox2"
Mask="999,9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="Left"
DisplayMoney="Left"
ErrorTooltipEnabled="True"/>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="AequorPubTracker.AequorDataDataContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" EntityTypeName=""
TableName="Aequor_Pub_Trackers">
</asp:LinqDataSource>
<asp:QueryExtender ID="QueryExtender1" runat="server" TargetControlID="LinqDataSource1">
<asp:SearchExpression SearchType="StartsWith" DataFields="PubId">
<asp:ControlParameter ControlID="SearchTextBox" />
</asp:SearchExpression>
</asp:QueryExtender>
</asp:Content>
You’re receiving this error becase the target control is nested in a databound control, and the extender is unable to find the target control. Try putting the
MaskedEditExtenderin theDetailsViewcontrol.