2012-05-24 3 views
0

Вот моя ситуация. У меня есть страница веб-форм, и это раздражает, когда вся страница прокручивается вверху каждого раза, когда вы нажимаете элемент управления, поэтому я пытаюсь применить панели обновлений к своей странице.Обновление всей страницы из обновленной панели

Кнопка отправки может быть или не быть нажата в зависимости от того, находится ли содержимое отдельных панелей обновлений в правильном состоянии.

Когда нажата кнопка отправки, она может потенциально повлиять на любой элемент управления на странице.

Я понимаю, что я могу сделать некоторые из этого с элементом тега <triggers> панели обновления, но я не хочу, чтобы все было на странице в панель обновления с его собственным триггером, я бы предпочел что кнопка отправки просто перезагружает всю страницу.

Для простоты я собрал образец проекта для представления моей страницы. Он имеет кнопку «Сброс», чтобы представить кнопку «отправить».

Мастер-страница:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head runat="server"> 
    <title></title> 
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" /> 
    <asp:ContentPlaceHolder ID="HeadContent" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form runat="server"> 
    <asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" /> 

    <div class="page"> 
     <div class="header"> 
      <div class="title"> 
       <h1> 
        My ASP.NET Application 
       </h1> 
      </div> 
      <div class="loginDisplay"> 
       <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false"> 
        <AnonymousTemplate> 
         [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ] 
        </AnonymousTemplate> 
        <LoggedInTemplate> 
         Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>! 
         [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ] 
        </LoggedInTemplate> 
       </asp:LoginView> 
      </div> 
      <div class="clear hideSkiplink"> 
       <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal"> 
        <Items> 
         <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/> 
         <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/> 
        </Items> 
       </asp:Menu> 
      </div> 
     </div> 
     <div class="main"> 
      <asp:ContentPlaceHolder ID="MainContent" runat="server"/> 
     </div> 
     <div class="clear"> 
     </div> 
    </div> 
    <div class="footer"> 

    </div> 
    </form> 
</body> 
</html> 

страница по умолчанию:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" 
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> 



<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 

</asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 

    <asp:Label runat=server Text="This lable represents things not in update panels" ID="label1"></asp:Label> 

    <asp:UpdatePanel ID="UpdatePanel1" runat=server> 
     <ContentTemplate> 
      <table> 
       <tr> 
        <td><asp:Button ID="button1" runat="server" OnClick="Button1_click" Text="Button 1" /></td> 
        <td><asp:TextBox ID="textBox1" runat="server" Text="StartText" Enabled="false" /></td> 
       </tr> 
      </table> 
     </ContentTemplate> 
    </asp:UpdatePanel> 

    <asp:UpdatePanel ID="UpdatePanel2" runat=server> 
     <ContentTemplate> 
      <table> 
       <tr> 
        <td><asp:Button ID="button2" runat="server" OnClick="Button2_click" Text="Button 2" /></td> 
        <td><asp:TextBox ID="textBox2" runat="server" Text="StartText" Enabled="false" /></td> 
       </tr> 
      </table> 
     </ContentTemplate> 
    </asp:UpdatePanel> 

    <asp:UpdatePanel ID="UpdatePanelReset" runat=server> 
     <ContentTemplate> 
      <asp:Button ID="reset" runat="server" OnClick="Reset_click" Text="reset" /> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="button1" EventName="click" /> 
      <asp:AsyncPostBackTrigger ControlID="button2" EventName="click" /> 
     </Triggers> 
    </asp:UpdatePanel> 

</asp:Content> 

Код позади

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Xml.Linq; 

namespace WebApplication1 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void Button1_click(object sender, EventArgs e) 
     { 
      textBox1.Enabled = !textBox1.Enabled; 
      reset.Enabled = !textBox1.Enabled && !textBox2.Enabled; 
     } 

     protected void Button2_click(object sender, EventArgs e) 
     { 
      textBox2.Enabled = !textBox2.Enabled; 
      reset.Enabled = !textBox1.Enabled && !textBox2.Enabled; 
     } 

     protected void Reset_click(object sender, EventArgs e) 
     { 
      textBox1.Text = "StartText"; 
      textBox2.Text = "StartText"; 
      label1.Text = "reset button clicked"; 
     } 
    } 
} 

ответ

1

Просто добавьте PostBackTrigger к последнему UpdatePanel.

<asp:PostBackTrigger ControlID="reset" /> 
Смежные вопросы