Adding the Immediate Preview Feature


To see the effect of the caption settings, users have to click the Preview button. This action causes the page to be posted back to the server, where the Click handler for the button runs and sets the sample caption. An interesting alternative is to have each control preview immediately. For example, when users pick a new color from the drop-down list, the results can show immediately. The page will still make a round trip to the server to apply the settings, but the users won t have to click the Preview button.

Preview the control settings immediately

  1. Open the SlideshowSetttings.aspx page.

  2. In Design view, select the DropDownList control, and in the Properties window, set the AutoPostBack property to True.

    When this property is set to True, the controls post the page to the Web server as soon as there s a change when the user selects an item in the drop-down list. When the page is posted, the handler for the control s default event is executed. In the drop-down list, when users select an item, the SelectedIndexChanged event is raised.

  3. Select the CheckBox control and set its AutoPostBack property to True also.

    When users click a check box or option button, the button raises the control s CheckedChanged event.

  4. Set the AutoPostBack property to True for each of the three RadioButton controls.

Right now, all the logic for doing the preview is in the buttonPreview_Click handler. However, you want to run the preview code from the events raised by all the separate controls. You ll create a single preview routine and then call it whenever you need to preview.

Create the preview routine

  1. Switch to Code view and scroll to the bottom of the page.

  2. Create a new method named Preview by typing in the following:

    Sub Previe End Sub

    It doesn t matter where the Preview method is located, as long as this method isn t inside another event handler.

  3. Copy the contents of the buttonPreview_Click handler (everything except the Sub and End Sub lines) into the Preview method, between the Sub Preview and End Sub lines.

  4. Inside the buttonPreview_Click handler, insert the following line, namely, the call to the Preview method:

    Sub buttonPreview_Click(sender As Object, e As  EventArgs     Preview( End Sub
  5. In Design view, double-click the DropDownList control to create a skeleton handler for the SelectedItemChanged event. Call Preview from that handler, too. It will look like this:

    Sub listColorNames_SelectedIndexChanged(sender  As Object,      e As EventArgs     Preview( End Sub
  6. Repeat step 5 for the check box and the option button controls, creating handlers for their CheckedChanged event. For example, the handler for the radioFontArial control will look like this:

    Sub radioFontArial_CheckedChanged(sender As Ob ject, e As EventArgs     Preview( End Sub

If you like, you can even remove the Preview button because it s redundant at this point.




Microsoft ASP. NET Web Matrix Starter Kit
Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
ISBN: 0735618569
EAN: 2147483647
Year: 2003
Pages: 169
Authors: Mike Pope
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net