javascript - ASP.NET updatepanel inside hidden panel possible bug - Stack Overflow

The JavaScript generated by the asp SciptManager control seems to have a bug and cant handle hidden Upd

The JavaScript generated by the asp SciptManager control seems to have a bug and cant handle hidden UpdatePanels. A JavaScript error is thrown when a control within one updated panel tries to make another update panel visible.

Is this a bug with ASP.Net AJAX? And does anyone have any ideas how to get around this?

Here is an example of what I'm trying to do

<script type="text/C#" runat="server">
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
    }
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="Show Panel"></asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:Panel ID="Panel1" runat="server" Visible="false">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            blah bla blah
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

This is the JavaScript error that gets thrown when clicking on the "LinkButton1" link. This error es from the JavaScript that is generated by the asp ScriptManager control

Error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder1_UpdatePanel2'

The JavaScript generated by the asp SciptManager control seems to have a bug and cant handle hidden UpdatePanels. A JavaScript error is thrown when a control within one updated panel tries to make another update panel visible.

Is this a bug with ASP.Net AJAX? And does anyone have any ideas how to get around this?

Here is an example of what I'm trying to do

<script type="text/C#" runat="server">
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
    }
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="Show Panel"></asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:Panel ID="Panel1" runat="server" Visible="false">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            blah bla blah
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

This is the JavaScript error that gets thrown when clicking on the "LinkButton1" link. This error es from the JavaScript that is generated by the asp ScriptManager control

Error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder1_UpdatePanel2'
Share edited Jun 23, 2011 at 23:51 Bill the Lizard 406k212 gold badges574 silver badges892 bronze badges asked May 27, 2010 at 2:41 MakkyNZMakkyNZ 2,2556 gold badges36 silver badges56 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You're running into problems because Panel1's contents are not rendered when the page is first rendered. This has the effect that UpdatePanel2 is not properly initialised.

(The page request manager, which manages all the partial updates, needs to be aware of UpdatePanel2's existence and this just won't happen if it is not rendered. Also, if you think about it, the update panel needs to render some elements if only to add a placeholder div into which it will inject its content on partial postbacks).

I don't know precisely what you are trying to achieve but, if you simply want your UpdatePanel2 to be triggered by a control that is not itself inside the update panel, then set LinkButton1 as a trigger like so.

<script runat="server">
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        blabla.Visible = true;
    }
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
</asp:ScriptManager>

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="Show Panel"></asp:LinkButton>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" >
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="LinkButton1" />
    </Triggers>
    <ContentTemplate>
        <asp:PlaceHolder runat="server" ID="blabla" Visible="false">
        blah bla blah
        </asp:PlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>

If LinkButton1 must indeed be inside an update panel (perhaps LinkButton1 is not always visible?) then you can do something like the following

<script runat="server">
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        blabla.Visible = true;
        UpdatePanel2.Update();
    }
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="Show Panel"></asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" >
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="LinkButton1" />
    </Triggers>
    <ContentTemplate>
        <asp:PlaceHolder runat="server" ID="blabla" Visible="false">
        blah bla blah
        </asp:PlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>

The error you get is not from the JavaScript, but from ASP.NET.

You get it because you try to make visible the Panel1, that is outside the UpdatePanel that you call it, and this is not possible.

Everything that you going to update on the web page must be inside the UpdatePanel that you call.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744919995a4601073.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信