How to get the button that is inside asp: UpdatePanel to refresh the whole page?

I have a button inside the refresh panel that I would like to refresh the whole page. I installed ChildrenAsTriggers="false"and UpdateMode="Conditional".

I have some sample code that demonstrates my problem.

<asp:UpdatePanel ID="myFirstPanel" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
   <ContentTemplate>
      <asp:Button runat="server" ID="myFirstButton" Text="My First Button" onclick="myFirstButton_Click" />
      <asp:Button runat="server" ID="mySecondButton" Text="My Second Button" onclick="mySecondButton_Click" />
   </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="mySecondPanel" runat="server">
   <ContentTemplate>
       <asp:Label runat="server" ID="myFirstLabel" Text="My First Label"></asp:Label>
    </ContentTemplate>
    <Triggers>
       <asp:AsyncPostBackTrigger ControlID="myFirstButton" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:Label runat="server" ID="mySecondLabel" Text="My Second Label"></asp:Label>

And the code behind:

protected void myFirstButton_Click(object sender, EventArgs e)
{
  myFirstLabel.Text = "Inside Panel " + DateTime.Now.ToString("mm:ss");
}
protected void mySecondButton_Click(object sender, EventArgs e)
{
  mySecondLabel.Text = "Outside Panel " + DateTime.Now.ToString("mm:ss");
}

I want to update a shortcut that is not inside the update panel when the second button is clicked. The second button should be on the update panel. I do not want to put a tab in the update panel.

+3
source share
6 answers

Try adding a PostBackTrigger to the first UpdatePanel, for the secound button. This will say that the update panel that the button should do a full postback.

+6
source

ScriptManager.GetCurrent().RegisterPostBackControl();

+4

PostBackTrigger , ,

<Triggers>
   <asp:PostBackTrigger ControlID="mySecondButton" />
</Triggers>

, . , .

+1

, , , . ( , @serkan. .) ASP.NET, , , , , . , , , , .

, , . . , Page_Load :

    protected void Page_Load(object sender, EventArgs e)
    {
        // If the chart is within an update panel then we need to tell the script manager
        // to not do an asynch postback on chartdownload.  If we don't, the download
        // doesn't work.
        var scriptManager = ScriptManager.GetCurrent(Page);
        if (scriptManager != null)
        {
            scriptManager.RegisterPostBackControl(ChartSaveButton);
        }
        // Rest of Page_Load followed here...

, ChartSaveButton, :

    private Control ChartSaveButton
    {
        get { return FindControl("btnDownloadChart"); }
    }

( "btnDownloadChart" - .)

, , , . , .

0

. , , ajax- , .

, , javascript .

-1

, - , . , . ajax , , , Response.Redirect(...) .

-2

Source: https://habr.com/ru/post/1698516/


All Articles