如何通过单击更新面板中的按钮来触发整个页面的回发

时间:2018-08-13 22:55:00

标签: javascript asp.net telerik entity-framework-6

这是updatepanel,我需要执行AsyncPostBackTrigger,以便在其他控件上运行一些脚本和代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <ContentTemplate>

          <telerik:RadButton ID="RadButton1" runat="server" SingleClick="true" SingleClickText="Processing..." AutoPostBack="true" OnClick="RadButton1_Click" Text="Create Order" Font-Bold="true" Font-Size="12" BackColor="#333333" ForeColor="White" Skin="Bootstrap" CssClass="auto-style5"  >
          </telerik:RadButton>

       </ContentTemplate>
       <Triggers>

           <asp:AsyncPostBackTrigger ControlID="RadButton1" EventName="Click" />

       </Triggers>
</asp:UpdatePanel>

点击功能

protected void RadButton1_Click(object sender, EventArgs e)
{ 
   ///some logic///
   /////DO PostBack Here///
}

1 个答案:

答案 0 :(得分:0)

请按照以下示例操作。删除适当的注释以体验其行为并学习。谢谢。 :)

aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TriggerPostBack.aspx.cs" Inherits="FredWebForm.TriggerPostBack" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <%-- removed OnClick="RadButton1_Click" from radio button--%>
            <asp:RadioButton ID="RadButton1" runat="server" SingleClick="true" SingleClickText="Processing..." AutoPostBack="true" Text="Create Order" Font-Bold="true" Font-Size="12" BackColor="#333333" ForeColor="White" Skin="Bootstrap" CssClass="auto-style5"></asp:RadioButton>
            <asp:Label ID="StuffInUpdatePanelChangesAsyncPostBackTrigger" runat="server" />
        </ContentTemplate>
        <Triggers>
            <%--<asp:AsyncPostBackTrigger ControlID="RadButton1" EventName="CheckedChanged" />--%>
            <asp:PostBackTrigger ControlID="RadButton1" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Label ID="StuffOutsideUpdatePanelNOCHANGEChangesAsyncPostBackTrigger" runat="server" />
</asp:Content>

后面的代码

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            StuffInUpdatePanelChangesAsyncPostBackTrigger.Text = "StuffInUpdatePanelChangesAsyncPostBackTrigger";
            StuffOutsideUpdatePanelNOCHANGEChangesAsyncPostBackTrigger.Text = "StuffOutsideUpdatePanelNOCHANGEChangesAsyncPostBackTrigger";
        }

    }