UserControl causes full postback in UpdatePanel

空扰寡人 提交于 2019-12-25 00:08:14

问题


I'm fighting this problem for few hours now and I'm not getting any closer to solution.

The thing is: I'm having few UpdatePanels on my master page. And then, I have RadTreeViewcontrol on the page, that should cause partial postback each time node is clicked. Everything works fine there.

Since I'm using the same tree on some other pages, I moved this functionality to UserControl. Stuff I've done before, so no problem. Moved some code to ascx, created some events. Everything always worked for me well. But not now.

RadTreeView is nested inside UserControl, and this control on master page with update panels, see below:

<asp:Panel ID="pnlContentWrapper" runat="server" CssClass="ContentWrapper">
    <div id="HeaderBreadCrumb">
        <asp:ContentPlaceHolder ID="HeaderBreadCrumbContent" runat="server" />
    </div>
    <div id="HeaderMenu">
        <asp:UpdatePanel ID="upnlTreeMenu" runat="server">
            <ContentTemplate>
                <asp:ContentPlaceHolder ID="HeaderMenuContent" runat="server" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="treeProductTree" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    <div id="TreeDiv">
                <fp:ProductTree ID="treeProductTree" runat="server" />
    </div>
    <asp:Panel ID="ContentDiv" ClientIDMode="Static" runat="server">
        <asp:UpdatePanel ID="upnlTreeContent" runat="server">
            <ContentTemplate>
                <asp:ContentPlaceHolder ID="TreePageContent" runat="server" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="treeProductTree" />
            </Triggers>
        </asp:UpdatePanel>
    </asp:Panel>
</asp:Panel>

And the user control is really simple:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ProductTree.ascx.vb"
Inherits="ProductTree" %>
<div>
<telerik:RadTreeView ID="treeProductTree" ClientIDMode="Static" runat="server" EnableDragAndDrop="false"
    SkinID="CustomSkin" CssClass="MasterProductTree" DataFieldID="NodeId" DataFieldParentID="NodeParentId"
    DataTextField="NodeName" DataValueField="NodeId" />
</div>

And some code behind:

Imports Telerik.Web.UI

Public Class ProductTree
    Inherits System.Web.UI.UserControl

    Public Event NodeExpand As EventHandler(Of ProductTreeNodeExpandEventArgs)

    Public Event SelectedNodeChange As EventHandler



    Protected Sub ProductTree_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) _
        Handles treeProductTree.NodeExpand
        Dim nodeId As Integer = CInt(e.Node.Value)
        Dim evetArgs = New ProductTreeNodeExpandEventArgs(nodeId)
        RaiseEvent NodeExpand(Me, evetArgs)

        //'some logic
    End Sub

    Protected Sub ProductTree_OnNodeClick(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) _
        Handles treeProductTree.NodeClick
        RaiseEvent SelectedNodeChange(Me, New System.EventArgs())
    End Sub

End Class

What I don't know is: why is this causing full postback instead of partial? I suspect that it may have something to do with raising my for SelectedNodeChange, but I don't know how to deal with it other way. I need to let other components know, that node selection changed. How can I improve this to make it work with UpdatePanels?


回答1:


Suspect that registering a UserControl as an AsyncPostbackTrigger is not going to get you very far. The UC itself is not a postback control, rather, it contains one. I would expose the tree control as a public property of the usercontrol, and then in code behind in your containing page, register the tree control itself as the trigger, rather than the UserControl.

Check this for a similar situation... it's not a great Q&A thread but it shows the basic gist.




回答2:


Well, I have the similar situation but it's a little more complicated.

User control causing postback is actually added dynamically depending on the request parameter value.

I was so glad the ClietIDMode paramter was added, I didn't think a problem like tat would be overlooked by Microsoft.




回答3:


The same problem that I am facing right now... I thing that could be fixed by wrapping up the UC with an iFrame.



来源:https://stackoverflow.com/questions/5424119/usercontrol-causes-full-postback-in-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!