SurveyQuestionsExample.aspx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. protected SortedList AnsweredQuestions
  6. {
  7. get { return (SortedList)(ViewState["AnsweredQuestions"] ?? new SortedList()); }
  8. set { ViewState["AnsweredQuestions"] = value; }
  9. }
  10. protected void Page_Load()
  11. {
  12. ScriptManager1.RegisterAsyncPostBackControl(SurveyDataList);
  13. }
  14. protected void ChoicesRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
  15. {
  16. SortedList answers = this.AnsweredQuestions;
  17. RadioButtonList r = (RadioButtonList)sender;
  18. answers[r.ToolTip] = r.SelectedValue;
  19. this.AnsweredQuestions = answers;
  20. ResultsList.DataSource = this.AnsweredQuestions;
  21. ResultsList.DataBind();
  22. if (this.AnsweredQuestions.Count == SurveyDataList.Items.Count)
  23. SubmitButton.Visible = true;
  24. UpdatePanel1.Update();
  25. }
  26. protected void SubmitButton_Click(object sender, EventArgs e)
  27. {
  28. // Submit responses.
  29. }
  30. </script>
  31. <html xmlns="http://www.w3.org/1999/xhtml">
  32. <head id="Head1" runat="server">
  33. <title>Registering Controls as Async Postback Controls</title>
  34. <style type="text/css">
  35. .AnswerFloatPanelStyle {
  36. background-color: bisque;
  37. position: absolute;
  38. right: 10px;
  39. height: 130px;
  40. width: 150px;
  41. border-right: silver thin solid; border-top: silver thin solid;
  42. border-left: silver thin solid; border-bottom: silver thin solid;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <form id="form1" runat="server">
  48. <div>
  49. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  50. <div id="AnswerFloatPanel" class="AnswerFloatPanelStyle" runat="server">
  51. <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
  52. <ContentTemplate>
  53. Completed Questions:
  54. <asp:DataList ID="ResultsList" runat="server">
  55. <ItemTemplate>
  56. <asp:Label ID="ResultQuestion" runat="server" Text='<%# Eval("Key") %>' />
  57. ::
  58. <asp:Label ID="ResultAnswer" runat="server" Text='<%# Eval("Value") %>' />
  59. </ItemTemplate>
  60. </asp:DataList>
  61. <p style="text-align: right">
  62. <asp:Button ID="SubmitButton" Text="Submit" runat="server" Visible="false"
  63. OnClick="SubmitButton_Click" />
  64. </p>
  65. <asp:Label ID="Message" runat="Server" />
  66. </ContentTemplate>
  67. </asp:UpdatePanel>
  68. </div>
  69. <asp:XmlDataSource ID="SurveyDataSource"
  70. runat="server"
  71. XPath="/Questions/Question"
  72. DataFile="~/App_Data/SurveyQuestions.xml"/>
  73. <asp:DataList
  74. ID="SurveyDataList"
  75. DataSourceID="SurveyDataSource"
  76. runat="server">
  77. <ItemTemplate>
  78. <table cellpadding="2" cellspacing="2">
  79. <tr>
  80. <td valign="top">
  81. <asp:Label id="QuestionLabel" Text='<%# XPath("@Title")%>' runat="server" />
  82. </td>
  83. </tr>
  84. <tr><td>
  85. <asp:RadioButtonList ID="ChoicesRadioButtonList" runat="server"
  86. DataSource='<%#XPathSelect("Choices/Choice") %>'
  87. DataTextField="InnerText" DataValueField="InnerText"
  88. AutoPostBack="True"
  89. ToolTip='<%# "Question" + XPath("@ID") %>'
  90. OnSelectedIndexChanged="ChoicesRadioButtonList_SelectedIndexChanged"/>
  91. </td></tr>
  92. </table>
  93. <hr />
  94. </ItemTemplate>
  95. </asp:DataList>
  96. </div>
  97. </form>
  98. </body>
  99. </html>