我编码如下所示,并且我在MaskedEditExtender标签中包含了TargetControlID,但我得到的是NullReferenceException:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Employee_Managment.Register" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="../Styles/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<asp:ScriptManager runat="server" ID="ScriptManager1" EnableScriptGlobalization="true"></asp:ScriptManager>
<%--<asp:TextBox runat="server" ID="autocompletetest"></asp:TextBox>
<ajax:AutoCompleteExtender runat="server" EnableCaching="false" CompletionInterval="10" MinimumPrefixLength="2" CompletionSetCount="3" TargetControlID="autocompletetest" ServiceMethod="NamePick" FirstRowSelected="false"></ajax:AutoCompleteExtender>
<asp:Label runat="server" ID="label"></asp:Label>--%>
<asp:TextBox ID="TextBox3" runat="server" Width="150px"></asp:TextBox>
<ajax:MaskedEditExtender ID="MaskedEditExtender2" runat="server" MaskType="None" Mask="9999" TargetControlID="TextBox3">
</ajax:MaskedEditExtender>
<%--<ajax:MaskedEditValidator ID="MaskedEditValidator2" runat="server" ControlToValidate="TextBox3" ControlExtender="MaskedEditExtender2" Display="Dynamic" IsValidEmpty="false" InvalidValueMessage="Invalid date!" EmptyValueMessage="The date is not entered">
</ajax:MaskedEditValidator> --%>
</body>
</html>
我收到错误,如下所示:
[NullReferenceException: Object reference not set to an instance of an object.]
AjaxControlToolkit.MaskedEditExtender.OnLoad(EventArgs e) +183
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2952
请评论解决方案。
答案 0 :(得分:0)
请参阅以下代码......这对我有用..
我为maskededit扩展器设置了相同的id并屏蔽了编辑验证器的控制器(这里我的maskededitextender的id是MaskedEditExtender1,我为Maskededitvalidator ControlExtender设置了相同的id)
<asp:TextBox id="txtStartTime" runat="server" placeholder="HH:mm" OnTextChanged="txtStartTime_TextChanged" AutoPostBack="true" ></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
AcceptAMPM="false" Mask="99:99" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
MaskType="Time" TargetControlID="txtStartTime" />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator4" runat="server"
ControlExtender="MaskedEditExtender1"
ControlToValidate="txtStartTime"
IsValidEmpty="True"
EmptyValueMessage="Time is required"
InvalidValueMessage="Time is invalid"
Display="Dynamic"
TooltipMessage="Input a time"
EmptyValueBlurredText="Invalid Time"
InvalidValueBlurredMessage="Invalid Time" />