listbox-databind-postback.aspx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- bug on 45493. Right now, I am getting an error other than the one on the bug. the original issue was:
  2. To reproduce the bug:
  3. 1. in xsp, start the following aspx page.
  4. 2. Select an exam, e.g. "calculus".
  5. 3. Click "view subscriptions". The list of subscription correctly
  6. appears.
  7. 4. Now click "view subscriptions" again, _without_ changing the
  8. selection (i.e. leave "calculus" selected). An error message appears,
  9. complaining that there was no exam selected. But it was!
  10. -->
  11. <%@ language="C#" %>
  12. <script runat="server" >
  13. void Page_Load(Object Source, EventArgs E) {
  14. if (!IsPostBack){
  15. #region fill the listbox exams
  16. exams.Items.Clear();
  17. exams.Items.Add(new ListItem( "math"));
  18. exams.Items.Add(new ListItem( "calculus"));
  19. exams.Items.Add(new ListItem( "english"));
  20. message_subscriptions.Visible=false;
  21. subscriptions.Visible=false;
  22. #endregion
  23. }
  24. else{
  25. if (exams.SelectedIndex >=0){
  26. message_subscriptions.Visible=true;
  27. subscriptions.Visible=true;
  28. message.Text="";
  29. message_subscriptions.Text = "Subscriptions to \"" + exams.SelectedItem.Text + "\" are:";
  30. subscriptions.Items.Clear();
  31. subscriptions.Items.Add(new ListItem( "John"));
  32. subscriptions.Items.Add(new ListItem( "Jack"));
  33. }
  34. else{
  35. message.Text = "<h2>Error: no item selected. SelectedIndex = " +
  36. exams.SelectedIndex + " </h2>";
  37. }
  38. }
  39. }
  40. </script>
  41. <html>
  42. <body>
  43. <asp:label id=message runat=server ForeColor=red/>
  44. <h1>Mono test page</h1>
  45. Select an exam, then click "view subscriptions".
  46. <form runat=server>
  47. <p><asp:listbox id="exams" runat=server />
  48. <p> <input type=submit value="View subscriptions">
  49. <p><asp:label id="message_subscriptions" runat=server />
  50. <p><asp:listbox id="subscriptions" runat=server />
  51. </form>
  52. </body>
  53. </html>