AJAX.Net - UpdatePanel doesn't delete old cont

2019-06-14 01:50发布

I'm using AJAX.Net (3.5) inside a usercontrol. The usercontrol contains an UpdatePanel, and inside the UpdatePanelthere is a MultiView. The ScriptManager is included in the page that act as container for the usercontrol.

To switch between views the usercontrol contains a simple button. When I click it, the View is changed so the old content is hidden and new content is displayed. My problem is that the content isn't hidden at all. The view changes and the new content is displayed, but the old one remains on the page. To isolate the problem, I tried changing the multiview and switching visibility of a simple label, but the behavior is the same. Any ideas?

3条回答
祖国的老花朵
2楼-- · 2019-06-14 02:13

It seems that AJAX.Net doesn't work very well if you have part of a table outside the UpdatePanel.

On my control I want to show or hide some rows of a table. I included only the tr and td tags inside the updatepanel.

To reproduce the problem:

<table>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        <tr>
            <td>
                <asp:Label ID="lblToShow" runat="server" Text="Label to show" Visible="false" />
                <br />
                <asp:Label ID="lblToHide" runat="server" Text="Label to hide" />
            </td>
        </tr>
    </ContentTemplate>
</asp:UpdatePanel>
</table>

If you change the visibility using:

lblToShow.Visible = true;
lblToHide.Visible = false;

The text of both labels are shown on the page (lblToHide does not hide)

If you move the table tags inside the UpdatePanel everything works fine.

查看更多
SAY GOODBYE
3楼-- · 2019-06-14 02:21

oh I understand. It's all right then. The problem is not of Ajax here. It's just you cannot embed something in <table> tags. In this case, you can try something different than the <table> control. Maybe a <div> or something else. I don't know exactly what sort of situation you have. Maybe you explain the result you want to achieve so I can give you some advice.

Regards

查看更多
何必那么认真
4楼-- · 2019-06-14 02:37

call

updatepanel.Update() 

after you make the changes to your updatepanel

or try

 updatepanel.Controls.Clear();
查看更多
登录 后发表回答