开发者

UserControl causes full postback in UpdatePanel

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 Select开发者_StackOverflow中文版edNodeChange 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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜