1

我有两个具有相同代码的“UpdatePanel、ScriptManager 和 CalendarExtender , in one of them, theCalendarExtender”的页面工作正常,但在另一个页面中,它给了我这个错误:

CalendarExtender is not a known Element

这是我的代码aspx

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolKit" TagPrefix="asp" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
   <div id="conteudo" style="text-align: left">                    
        <fieldset id="fieldset" style="width:730px; margin-left: -200px">
        <legend style="text-align:center;"><b>Detalhes do Chamado</b></legend>                                   
        <div id="DetalhesChamado">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" EnablePartialRendering="true"></asp:ScriptManager>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
            //Here is a gridview  
            <asp:CalendarExtender runat="server"></asp:CalendarExtender>

但仍然给出错误...

--更新2--

现在我收到此错误:
The TargetControlID of 'CalendarExtender1' is not valid. A control with ID 'TxtPrevisao' could not be found.

我的新代码:

<asp:TemplateField>
    <ItemTemplate>
        <asp:TextBox ID="TxtPrevisao" runat="server" Width="115px"></asp:TextBox>
        <asp:CalendarExtender ID="CalendarExtender1" runat="server" Format=" dd ,MMMM ,yyyy" TargetControlID="TxtPrevisao" PopupButtonID="TxtPrevisao" CssClass="MyCalendar">
        </asp:CalendarExtender>
     </ItemTemplate>
</asp:TemplateField>
4

2 回答 2

3

更改 Ajax-Kit 的 Tag-Prefix 并查看它是否正常工作

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>

并且:

<act:CalendarExtender runat="server"></act:CalendarExtender>

asp 用于 Asp.Net 组件,例如 UpdatePanel

------------ 更新 2 --------

对于您的新错误,您无法将 PopupButtonID 分配给文本框,您需要一个 ImageButton

<asp:ImageButton ID="btnCalenderPopup" runat="server" ImageUrl="App_Themes/Standard/Img/calendar.png" CausesValidation="False" />

不过,我坚持认为,您需要正确分配 Took-Kit 的标签前缀,并且您需要正确引用组件,如 SanjeevRai 所说

于 2013-03-13T12:14:25.780 回答
1

You have to add reference of 'Ajaxtoolkit' dll into your project. It seems like it is not getting the proper reference of 'AjaxToolkit' DLL.

You can check references of your project by right clicking on website and select 'Property Pages' option. then it will show you all the references. from here you can check whether 'Ajaxtoolkit' reference exit in your project or not.

If Ajaxtoolkit reference does not exist in your project then you will have to add this reference first!

------------ Update 2 -------------------

After looking at your code I got the issue.

Actually you are using calenderextender and its TargetControlID textbox inside a gridview, so it is not getting the id of textbox.It will never identify the child control id directly on aspx page. you need to attach 'TargetControlID' and 'PopupButtonID' at run time inside RowDataBound event of gridview.

Here is a sample of code that you can use in you aspx.cs file:

void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TextBox txt = (TextBox)e.Row.FindControl("TxtPrevisao");
        CalendarExtender Calendar1 = (CalendarExtender)e.Row.FindControl("CalendarExtender1");
        Calendar1.TargetControlID=txt.ID;
        Calendar1.PopupButtonID=txt.ID;
    }
}

And in .aspx page attach the rowdatabound event to grid and remove 'TargetControlID' and 'PopupButtonID' attributes from calenderextender i.e.

<asp:TemplateField>
    <ItemTemplate>
        <asp:TextBox ID="TxtPrevisao" runat="server" Width="115px"></asp:TextBox>
        <asp:CalendarExtender ID="CalendarExtender1" runat="server" Format=" dd ,MMMM ,yyyy" CssClass="MyCalendar">
        </asp:CalendarExtender>
     </ItemTemplate>
</asp:TemplateField>
于 2013-03-13T12:20:39.077 回答