ASP.NET 3.5 Unleashed Errata: Listing 31.6 and Listing 31.24
There are two mistakes in Chapter 31, Using Server-Side ASP.NET AJAX, both related to a last minute change to the ListView control. Microsoft changed the ListView control to require an itemPlaceholder instead of an itemContainer element in its LayoutTemplate. I managed to update the other code samples related to the ListView control in the book, but I neglected to update Chapter 31 (I forgot that I used the ListView control in this chapter).
The correct code for Listing 31.6 is:
1: <%@ Page Language="C#" %>
2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3: <html xmlns="http://www.w3.org/1999/xhtml">
4: <head runat="server">
5: <title>Nested UpdatePanels</title>
6: <style type="text/css">
7: fieldset
8: {
9: padding: 10px;
10: }
11: .comment
12: {
13: padding: 10px;
14: border: dotted 2px black;
15: margin: 10px;
16: }
17: </style>
18: </head>
19: <body>
20: <form id="form1" runat="server">
21: <div>
22: <asp:ScriptManager
23: id="sm1"
24: Runat="server" />
25: Page Time: <%= DateTime.Now.ToString("T") %>
26: <br />
27: <asp:DropDownList
28: id="ddlMovie"
29: DataSourceID="srcMovies"
30: DataValueField="Id"
31: DataTextField="Title"
32: AutoPostBack="true"
33: Runat="server" />
34: <asp:SqlDataSource
35: id="srcMovies"
36: ConnectionString='<%$ ConnectionStrings:con %>'
37: SelectCommand="SELECT Id, Title FROM Movie"
38: Runat="server" />
39: <br /><br />
40: <asp:UpdatePanel ID="upOuter" UpdateMode="Conditional" runat="server">
41: <Triggers>
42: <asp:AsyncPostBackTrigger ControlID="ddlMovie" />
43: </Triggers>
44: <ContentTemplate>
45: Outer UpdatePanel Time: <%= DateTime.Now.ToString("T") %>
46: <br />
47: <asp:FormView
48: id="frmMovie"
49: DataSourceID="srcMovie"
50: Runat="server">
51: <ItemTemplate>
52: <fieldset>
53: <legend>Movie</legend>
54: Title: <%# Eval("Title") %>
55: <br />
56: Director: <%# Eval("Director") %>
57:
58: <asp:UpdatePanel ID="upInner" runat="server">
59: <ContentTemplate>
60: <asp:ListView
61: id="lstMovieComments"
62: DataSourceID="srcMovieComments"
63: InsertItemPosition="FirstItem"
64: Runat="server">
65: <LayoutTemplate>
66: <fieldset>
67: <legend>Comments</legend>
68: Inner UpdatePanel Time: <%# DateTime.Now.ToString("T") %>
69: <asp:PlaceHolder id="itemPlaceHolder" runat="server" />
70: </fieldset>
71: </LayoutTemplate>
72: <ItemTemplate>
73: <div class="comment">
74: <%# Eval("Comment") %>
75: </div>
76: </ItemTemplate>
77: <InsertItemTemplate>
78: <asp:Label
79: id="lblComment"
80: Text="Comment:"
81: AssociatedControlID="txtComment"
82: Runat="server" />
83: <br />
84: <asp:TextBox
85: id="txtComment"
86: Text='<%# Bind("Comment") %>'
87: TextMode="MultiLine"
88: Columns="40"
89: Rows="3"
90: Runat="server" />
91: <br />
92: <asp:Button
93: id="btnInsert"
94: Text="Add Comment"
95: CommandName="Insert"
96: Runat="server" />
97: </InsertItemTemplate>
98: </asp:ListView>
99: </ContentTemplate>
100: </asp:UpdatePanel>
101: <asp:SqlDataSource
102: id="srcMovieComments"
103: ConnectionString='<%$ ConnectionStrings:con %>'
104: SelectCommand="SELECT Id, Comment
105: FROM MovieComment
106: WHERE MovieId=@MovieId"
107: InsertCommand="INSERT MovieComment (Comment,MovieId)
108: VALUES (@Comment,@MovieId)"
109: Runat="server">
110: <SelectParameters>
111: <asp:ControlParameter Name="MovieId" ControlID="ddlMovie" />
112: </SelectParameters>
113: <InsertParameters>
114: <asp:ControlParameter Name="MovieId" ControlID="ddlMovie" />
115: </InsertParameters>
116: </asp:SqlDataSource>
117: </fieldset>
118: </ItemTemplate>
119: </asp:FormView>
120: </ContentTemplate>
121: </asp:UpdatePanel>
122: <asp:SqlDataSource
123: id="srcMovie"
124: ConnectionString='<%$ ConnectionStrings:con %>'
125: SelectCommand="SELECT Id, Title, Director
126: FROM Movie
127: WHERE Id=@Id"
128: Runat="server">
129: <SelectParameters>
130: <asp:ControlParameter Name="Id" ControlID="ddlMovie" />
131: </SelectParameters>
132: </asp:SqlDataSource>
133: </div>
134: </form>
135: </body>
136: </html>
Notice that I also updated the way that the current time is displayed for this code sample. I changed:
Inner UpdatePanel Time: <%= DateTime.Now.ToString("T") %>
To:
Inner UpdatePanel Time: <%# DateTime.Now.ToString("T") %>
The correct code for Listing 31.24 is:
1: <%@ Page Language="C#" %>
2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3: <html xmlns="http://www.w3.org/1999/xhtml">
4: <head runat="server">
5: <title>Timer Messages</title>
6: <style type="text/css">
7: .message
8: {
9: margin-left: 20px;
10: font-style:italic;
11: }
12: </style>
13: </head>
14: <body>
15: <form id="form1" runat="server">
16: <asp:ScriptManager ID="sm1" runat="server" />
17: <asp:Timer ID="Timer1" Interval="5000" runat="server" />
18: <asp:UpdatePanel ID="up1" runat="server">
19: <Triggers>
20: <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
21: </Triggers>
22: <ContentTemplate>
23: Last Refresh <%= DateTime.Now.ToString("T") %>
24: <hr />
25: <asp:ListView
26: id="lstMessages"
27: DataSourceID="srcMessages"
28: Runat="server">
29: <LayoutTemplate>
30: <asp:Placeholder id="itemPlaceholder" runat="server" />
31: </LayoutTemplate>
32: <ItemTemplate>
33: <div>
34: Posted by <%# Eval("PostedBy") %>
35: <div class="message">
36: <%# Eval("Post") %>
37: </div>
38: </div>
39: </ItemTemplate>
40: </asp:ListView>
41: </ContentTemplate>
42: </asp:UpdatePanel>
43: <asp:ObjectDataSource
44: id="srcMessages"
45: TypeName="Message"
46: SelectMethod="Select"
47: Runat="server" />
48: </form>
49: </body>
50: </html>
Thank you Nikolay for pointing out these errors.