Ajax对WebPart的无刷新使用!

<%@ Page language="C#" MasterPageFile="~/MasterPage.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

  <asp:WebPartManager ID="WebPartManager1" runat="server" Personalization-Enabled="true" />
  <ajax:ajaxpanel ID="Ajaxpanel1" runat="server">
 
  <fieldset>
    <legend>ASP.NET 2.0 WebParts demo <asp:LinkButton runat="server" id="Toggle" Text="[Switch to EditMode]" OnClick="Toggle_Click" /></legend>
    <i>Very cool demo of ASP.NET 2.0 WebParts running on MagicAjax.<br />Switch to EditMode and move/add/delete WebParts without a visible postback.<br />
    Note: Your modifications are stored in Session, so will be lost when you leave this site.<br />
    Note2: Dragging and dropping of WebParts is a ASP.NET 2.0 feature that is only supported for IE.</i><br /><br />
    <table width="100%"><tr><td valign="top" style="width:30%">
      <asp:WebPartZone runat="server" ID="WebPartZone1" Width="100%">
          <PartTitleStyle CssClass="WebPartTitle" BackColor="LightBlue" />
          <ZoneTemplate>
            <uc1:Logo ID="Logo1" runat="server" />
          </ZoneTemplate>
      </asp:WebPartZone>
      </td><td valign="top" style="width:30%">
      <asp:WebPartZone  runat="server" ID="WebPartZone2" Width="100%">
          <PartTitleStyle CssClass="WebPartTitle" BackColor="LightBlue" />
          <ZoneTemplate>
            <uc1:Calendar ID="Calendar1" runat="server" />
          </ZoneTemplate>
      </asp:WebPartZone>
      </td><td style="width:10%">&nbsp;
    </td><td valign="top" style="width:30%">
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <HeaderStyle BackColor="Khaki" />
        <FooterStyle BackColor="Khaki" />
        <CloseVerb Visible="false" />
        <HeaderCloseVerb Visible="false" />
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server" Title="Catalog">
            <WebPartsTemplate>
              <uc1:Logo ID="Logo1" runat="server" />
              <uc1:Calendar ID="Calendar1" runat="server" />
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
    </td></tr></table>
  </fieldset>
  </ajax:ajaxpanel>
</asp:Content>

<script language="C#" runat="server">
 
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      // Force setting of Session id (workaround for bug in MagicAjax)
      Session["dummy"] = "dummy";
     
      // Authenticate as dummy user, so WebPartManager will allow switching to editmode
      FormsAuthentication.SetAuthCookie("Dummy", false);
    }
  }

  protected void Toggle_Click(object sender, EventArgs e)
  {
    if (WebPartManager1.DisplayMode == WebPartManager.BrowseDisplayMode)
    {
      Toggle.Text = "[Switch to ViewMode]";
      WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
    }
    else
    {
      Toggle.Text = "[Switch to EditMode]";
      WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
    }
  }
</script>

posted @ 2007-09-07 12:55  阳光囧男  阅读(361)  评论(0编辑  收藏  举报