被生活干了

无论你说的话多么傻逼,但我坚决捍卫你说话的权利

导航

UpdatePanel_Atlas

利用atlas制作的无刷新实例:
1button 2 validator3tree
aspx:

  1<%@ Page Language="C#"  %>
  2
  3<%@ Register Src="UpdatePanelUC_cs.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
  4
  5<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  6
  7<script runat="server">
  8
  9    protected void btnCopy_Click(object sender, EventArgs e)
 10    {
 11        lblFirstLineShipping.Text   = lblFirstLineBilling.Text;
 12        lblSecondLineShipping.Text  = lblSecondLineBilling.Text;
 13        lblThirdLineShipping.Text   = lblThirdLineBilling.Text;
 14    }

 15
 16    protected void btnUC_Click(object sender, EventArgs e)
 17    {
 18        WebUserControl1.Text = "You entered: " + Server.HtmlEncode(txtMessage.Text);
 19    }

 20
 21    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
 22    {
 23        String path = TreeView1.SelectedNode.DataPath;
 24        XmlDataSource2.XPath = path;
 25        DataList1.DataSource = XmlDataSource2;
 26        DataList1.DataBind();
 27    }

 28
 29    protected void Page_Load(object sender, EventArgs e)
 30    {
 31    }

 32
 33    protected void Button1_Click(object sender, EventArgs e)
 34    {
 35        Control c = this.LoadControl("updatepaneluc_cs.ascx");
 36        UpdatePanel4.Controls[0].Controls.Add(c);
 37    }

 38
 39    protected void Button2_Click(object sender, EventArgs e)
 40    {
 41        Control c = this.LoadControl("updatepaneluc1_cs.ascx");
 42        UpdatePanel4.Controls[0].Controls.Add(c);
 43    }

 44</script>
 45
 46<html xmlns="http://www.w3.org/1999/xhtml" >
 47<head id="Head1" runat="server">
 48    <style>
 49        .start{background-color:yellow;border:dashed 2px black;}
 50        .hover{font-size:40pt;background-color:yellow;border:dashed 2px black;}
 51    </style>
 52    <link href="intro.css" type="text/css" rel="Stylesheet" />
 53    <title>ASP.NET &quot;Atlas&quot; Demo: UpdatePanel Control</title>
 54</head>
 55<body>
 56    <form id="form1" runat="server">
 57        <asp:Image ID="Image2" runat="server" ImageUrl="images/banner1.gif" />
 58        <div id="Div1" class="title">
 59            <h2>ASP.NET &quot;Atlas&quot; Demo: Server-side Controls</h2>
 60            The following ASP.NET &quot;Atlas&quot; server-side controls are shown in this example:
 61            <ol>
 62            <li>&lt;atlas:UpdatePanel&gt;</li>
 63            </ol>
 64            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="NoUpdatePanel1_cs.aspx">Compare this with a page not using UpdatePanel</asp:HyperLink>
 65        </div>
 66        <div class="description">
 67            <atlas:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true" />
 68            <hr />
 69            <h3><u>
 70           Example 1:  Atlas:UpdatePanel</u></h3>
 71            The UpdatePanel shown in this example updates the 'Shipping Address' once the 'Same
 72            As Billing Address' button is clicked. Notice that the page doesn't postback and
 73            the refresh happens without requiring to reload all the current content on the page.<br />
 74            <br />
 75            <strong><span style="text-decoration: underline">Billing Address</span>:<br /></strong>
 76            <asp:Label ID="lblFirstLineBilling" runat="server" Font-Bold="False" Text="One Microsoft Way,"></asp:Label><br />
 77            <asp:Label ID="lblSecondLineBilling" runat="server" Text="Redmond,"></asp:Label><br />
 78            <asp:Label ID="lblThirdLineBilling" runat="server" Text="WA - 98052"></asp:Label><br />
 79            <br />
 80            <atlas:UpdatePanel runat="server" ID="UpdatePanel1">
 81                <ContentTemplate>
 82                    <strong><span style="text-decoration: underline">Shipping Address</span>:</strong>
 83                        <br />
 84                    <asp:Label ID="lblFirstLineShipping" runat="server" Font-Bold="False"></asp:Label><br />
 85                    <asp:Label ID="lblSecondLineShipping" runat="server"></asp:Label><br />
 86                    <asp:Label ID="lblThirdLineShipping" runat="server"></asp:Label><br />
 87                    <asp:Button ID="btnCopy" runat="server" Text="Same As Billing Address" OnClick="btnCopy_Click" CausesValidation="False" /><br />
 88                </ContentTemplate>
 89            </atlas:UpdatePanel>
 90            <br />
 91                
 92            <hr />
 93            <h3><u>Example 2: UpdatePanel, validation and usercontrols</u></h3>
 94            This example demonstrates the usage of UpdatePanel with validation controls, thus exemplifying
 95            the compatibility with other controls that might affect PostBack behavior. Notice
 96            that the UpdatePanel refresh does not happen unless the page is valid.<br />
 97            <br />
 98            Enter text in the textbox and click button to update user control content:
 99            <asp:TextBox ID="txtMessage" runat="server" />            
100            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtMessage"
101                Display="Dynamic" ErrorMessage="Input is required"></asp:RequiredFieldValidator><br />
102            <br />
103            <atlas:UpdatePanel runat="server" ID="UpdatePanel4">
104                <ContentTemplate>
105                    <asp:Button ID="btnUC" runat="server" Text="Update UserControl" OnClick="btnUC_Click" /><br />
106                    <uc1:WebUserControl ID="WebUserControl1" runat="server" />
107                </ContentTemplate>
108            </atlas:UpdatePanel>
109            <br />
110            <hr />
111            <h3><u>Example 3: Atlas:UpdatePanel in a Master-Details scenario</u></h3>
112            The following example demonstrates the usability of UpdatePanel control in the Master-Details scenario, the bindings are updated automatically on the treenode selection change, the page is not fully reconstructed but incrementally updated.<br />
113            <br />
114            &nbsp;
115                        <atlas:UpdatePanel runat="server" ID="UpdatePanel5">
116                            <ContentTemplate>
117                                        <table style="width: 556px">
118                <tr>
119                    <td style="width: 255px">
120                        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="artists.xml" XPath="Music/Artists/Timeline">
121                        </asp:XmlDataSource>
122                        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
123                            <DataBindings>
124                                <asp:TreeNodeBinding DataMember="Timeline" SelectAction="SelectExpand" TextField="id" />
125                                <asp:TreeNodeBinding DataMember="Artist" TextField="name" />
126                            </DataBindings>
127                        </asp:TreeView>
128                    </td>
129                    <td >
130
131                                &nbsp;<asp:XmlDataSource ID="XmlDataSource2" runat="server" DataFile="artists.xml">
132                                </asp:XmlDataSource>
133                                <asp:DataList ID="DataList1" runat="server">
134                                  <ItemTemplate>
135                                      <span style="font: 10pt verdana;"><u><b>Artist Details</b></u></span>
136                                      <table width="350px" style="font: 8pt verdana">
137                                        <tr><td><b>Name:</b></td><td><%# XPath("@name")%></td></tr>
138                                        <tr><td><b>Top Hit:</b></td><td><%# XPath("@hitSingle")%></td></tr>
139                                      </table>            
140                                  </ItemTemplate>
141                                </asp:DataList>
142                            
143                    </td>
144                </tr>
145            </table>
146            </ContentTemplate>
147            </atlas:UpdatePanel>            
148            <br />
149            <br />
150            <asp:Image ID="Image1" runat="server" ImageUrl="images/banner1.gif" /></div>
151    </form>
152</body>
153</html>
154



ascx:

 1<%@ Control Language="C#" ClassName="WebUserControl" %>
 2
 3<script runat="server">
 4
 5    public string Text
 6    {
 7        get
 8        {
 9            return myLabel.Text;
10        }

11        set
12        {
13            myLabel.Text = value;
14        }

15    }

16
17</script>
18
19<asp:Label runat="server" ID="myLabel" >Empty UserControl</asp:Label><br />
20


xml:

 1<?xml version="1.0" encoding="utf-8" ?>
 2<Music>
 3  <Artists>
 4    <Timeline id="60s">
 5      <Artist name="The Beatles" hitSingle="Help!" />
 6      <Artist name="Don Williams" hitSingle="It Must Be Love"  />
 7      <Artist name="Cliff Richard" hitSingle="Congratulations" />
 8      <Artist name="John Denver" hitSingle="Rocky Mountain High"/>
 9    </Timeline>
10    <Timeline id="70s">
11      <Artist name="Jethro Tull" hitSingle="Locomotive Breath" />
12      <Artist name="Pink Floyd" hitSingle="One Of These Days" />
13      <Artist name="Bob Dylan" hitSingle="Knockin' On Heaven's Door"/>
14    </Timeline>
15    <Timeline id="80s">
16      <Artist name="Dire Straits" hitSingle="Walk Of Life" />
17      <Artist name="U2" hitSingle="Where The Streets Have No Name" />
18      <Artist name="Duran Duran" hitSingle="Rio" />
19      <Artist name="Madonna" hitSingle="La Isla Bonita"/>
20      <Artist name="Michael Jackson" hitSingle="Thriller" />      
21    </Timeline>
22  </Artists>
23</Music>
24

posted on 2006-04-27 12:56  komazhang  阅读(342)  评论(0编辑  收藏  举报