开发者

DomEvent. AddHandler

I am facing little issue in my web application in asp.net. i am receiving the below error :

Error: Sys.InvalidOperationException: Handler was 开发者_StackOverflow社区not added through the Sys.UI.DomEvent.addHandler method.

I have used Updatepanel and this error occurs when i try to do some 2-3 actions very quickly. and when next time i try to do take some action my web application just hungs up. Please suggest. Thanks


In my case this was caused by having the 'Close' control within an Update Panel in the Modal Popup. I fixed it by creating a 'dummy' button outside of the Update Panel, and setting it as the 'CancelControlID' in the MPE attributes:

<asp:Button ID="btnDummyCloseWindow" runat="server" Style="visibility: hidden"/>

<ajaxToolkit:ModalPopupExtender ID="mpeWindow" runat="server" PopupControlID="pnlWindow"
    TargetControlID="btnDummyOtherButton" BackgroundCssClass="modalBackground"
    DropShadow="false" CancelControlID="btnDummyCloseWindow" />

You'll need to make sure the close button that is present within your Update Panel has actions assigned to it to close the window (e.g. mpeWindow.hide()).

It's also worth noting that I was also making use of the TargetControlID 'fix' too, where a dummy button is referenced, so ignore the TargetControlID attribute there.


I've solved the problem setting ScriptMode property of ScriptManager to Release instead of Debug By default ScriptManager is set to Debug mode.


I had the same problem and solved by placing the ModalPopupExtender or the user control that uses ModalPopupExtender inside an update panel.


Which ever way you want to look at it, the problem is inherit in what I believe is a bug in AJAX.

The only way I was able to resolve this was to control your Sorting or Paging on the server side where you control or more specifically refresh the UpdatePanel along with making sure the ModalPopup has been kept visible!

The reason for the error is really because once you do a sort of page change on a GridView that's inside an UpdatePanel, the controls have been "lost" to the UpdatePanel.

A better explanation is here.

Here is a column from my GridView...

    <asp:GridView ID="gvTETstudents" runat="server" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" ForeColor="#333333" Font-Size="Small" Width="100%"
      DataSourceID="sdsTETstudents" 
      OnRowCreated="gvTETstudents_RowCreated" 
      OnRowDataBound="gvTETstudents_RowDataBound" 
      OnDataBound="gvTETstudents_DataBound">
    <Columns>
        ..
        ..
        <ItemTemplate>
            <asp:UpdatePanel ID="upWEF1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnWEFCLOSE" />
                </Triggers>
                <ContentTemplate>
...
...
                    <asp:Panel ID="pnlWEF2" runat="server" style="display:none;">
                        <table><tr><td>
                        <asp:Button ID="btnWEFshow" runat="server" 
                            Text="ALL" 
                            Font-Size="Small" Font-Names="Arial" 
                            ToolTip="Click here to see all of this student's work experience feedback on file" />
                        <ajaxToolkit:ModalPopupExtender ID="mpeWEF" runat="server"
                            BackgroundCssClass="modalBackground"
                            OkControlID="btnWEFCLOSE"
                            PopupControlID="upWEF2"
                            TargetControlID="btnWEFshow">
                        </ajaxToolkit:ModalPopupExtender>
                        <asp:UpdatePanel ID="upWEF2" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <asp:Panel ID="pnlWEF3" runat="server" CssClass="pnlEndorsed">
                                    <div id="Hdr" style="text-align: center">
                                        <asp:Label ID="lblWEFHdr" runat="server">** CONTACT LOG **</asp:Label>
                                    </div>
                                    <div id="Bdy">
                                        <table style="width:100%"><tr><td>
                                        <asp:GridView ID="gvWEFContactLog" runat="server" 
                                            Font-Size="X-Small" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" AllowSorting="True" AutoGenerateColumns="False" Width="100%" 
                                            DataKeyNames="StudentContactLogID,Private,ApprenticeContactLogID"
                                            DataSourceID="sdsWEF"
                                            OnRowDataBound="gvWEFContactLog_RowDataBound"
                                            OnPageIndexChanging="gvWEFContactLog_PageIndexChanging" 
                                            OnSorted="gvWEFContactLog_Sorted">
                                            <Columns>
                                                <asp:TemplateField HeaderText="First Entered" SortExpression="FirstEntered">
                                                    <ItemTemplate>
                                                        <asp:HiddenField ID="hfWEFStudCLid" runat="server" Value='<%# Eval("StudentContactLogID") %>' />
                                                        <asp:HiddenField ID="hfWEFAppCLid" runat="server" Value='<%# Eval("ApprenticeContactLogID") %>' />
                                                        <asp:HiddenField ID="hfPrivate" runat="server" Value='<%# Eval("Private") %>' />
                                                        <asp:HiddenField ID="hfNotes" runat="server" Value='<%# Eval("ContactNotes") %>' />
                                                        <asp:LinkButton ID="lnkWEFCLOG" runat="server"
                                                            Text='<%# Eval("FirstEntered","{0:d MMM yyyy HH:mm}") %>'></asp:LinkButton>
                                                        <a id="lnkDummy" runat="server" visible=false></a>
                                                        <ajaxToolkit:ModalPopupExtender ID="mpeWEFCLOG" runat="server"
                                                            OkControlID="btnWEFCLOSEview"
                                                            PopupControlID="upWEFCLOG"
                                                            TargetControlID="lnkWEFCLOG">
                                                        </ajaxToolkit:ModalPopupExtender>
                                                        <asp:UpdatePanel ID="upWEFCLOG" runat="server" UpdateMode="Conditional">
                                                            <ContentTemplate>
                                                                <div id="pnlWEFCLOG" runat="server" class="pnlCLOG">
                                                                    <asp:TextBox ID="txtWEFCLOG" runat="server" 
                                                                        Wrap="true" 
                                                                        TextMode="MultiLine"
                                                                        Rows="10" 
                                                                        ReadOnly="true"
                                                                        Width="98%">
                                                                    </asp:TextBox>
                                                                    <br />
                                                                    <asp:Button ID="btnWEFCLOSEview" runat="server" Text="OK" Width="100%" />
                                                                </div>
                                                            </ContentTemplate>
                                                        </asp:UpdatePanel>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
                                                <asp:BoundField Visible="False" DataField="StudentContactLogID" HeaderText="LogID"
                                                    InsertVisible="False" ReadOnly="True" SortExpression="StudentContactLogID">
                                                    <ItemStyle HorizontalAlign="Center" />
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                </asp:BoundField>
                                                <asp:BoundField DataField="StaffName" HeaderText="Staff" ReadOnly="True" SortExpression="StaffName" />
                                                <asp:TemplateField HeaderText="Contact Date Time" SortExpression="ContactDateTime">
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactDateTime","{0:d MMM yyyy HH:mm}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Follow-Up Date" SortExpression="FollowUpDate">
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("FollowUpDate","{0:d MMM yyyy}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="Private" HeaderText="Private" SortExpression="Private" />
                                            </Columns>
                                            <EmptyDataTemplate>
                                                No Current Entries
                                            </EmptyDataTemplate>
                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                            <EditRowStyle BackColor="#999999" />
                                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                        </asp:GridView>
                                        <asp:SqlDataSource ID="sdsWEF" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
                                            SelectCommand="spTETStudentContactLogView" SelectCommandType="StoredProcedure">
                                            <SelectParameters>
                                                <asp:Parameter Name="StudentID" Type="string" />
                                                <asp:Parameter Name="WEF" Type="string" DefaultValue="%" />
                                            </SelectParameters>
                                        </asp:SqlDataSource>
                                        </td></tr>
                                        <tr style="text-align: center">
                                            <td style="text-align: left">
                                                <asp:Button ID="btnWEFCLOSE" runat="server" 
                                                    Text="CLOSE" 
                                                    CausesValidation="false" Font-Bold="True" Width="61px" />
                                            </td>
                                        </tr>
                                        </table>
                                    </div>
                                </asp:Panel>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        </td></tr></table>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
        </ItemTemplate>

The major point of the code above is that I have a very deep GridView inside an UpdatePanel that's inside a ModalPopUp.

Now look at what I have inside that GridView:

OnPageIndexChanging

and

OnSorted

Inside the GridView, there is another ModalPopup and TextBox. Ignore that. That's only so the user can see the comments from the student's contact log as another popup window.

So if we now go to the code behind for the above two events:

protected void gvWEFContactLog_Sorted(object sender, EventArgs e)
{
    GridView gvWEFCL = (GridView)sender;
    GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;

    UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
    if (upWEF1 != null) upWEF1.Update();

    AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
    if (mpeWEF != null) mpeWEF.Show();
}

protected void gvWEFContactLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView gvWEFCL = (GridView)sender;
    GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;

    UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
    if (upWEF1 != null) upWEF1.Update();

    AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
    if (mpeWEF != null) mpeWEF.Show();
}

Notice that I am not actually controlling the sorting or the paging itself. I am only forcing the GridView to call upon the main UpdatePanel (upWEF1) to refresh itself via an Update() call. The next step is to grab the ModalPopup I want to keep visible and re-Show() it!

And that's all there is to it!

I am sure there is a cleaner solution using JavaScript itself, but for me this avoids that dread meaningless error and I have a clean set of popups and update panels that can handle both hotlinks, sorting and paging as I want the GridView to perform!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜