tailieunhanh - ASP.NET 4 Unleased - p 37
Creating Custom Controls with User Controls /// /// Execute the step’s NextStep() method /// and move to the next step /// protected void btnNext_Click(object sender, EventArgs e) { bool success = ((IWizardStep)_currentStep).NextStep(); if (success) { if (StepIndex /// Move to the previous step /// protected void btnPrevious_Click(object sender, EventArgs e) { if (StepIndex 0) { StepIndex--; LoadWizardStep(); } } html { font:14px Georgia,Serif; } fieldset { display:block; width:600px; padding:20px; margin:10px; } Wizard From the Library of Wow! eBook Dynamically Loading User Controls 335 . | 334 CHAPTER 7 Creating Custom Controls with User Controls summary Execute the step s NextStep method and move to the next step summary protected void btnNext_Click object sender EventArgs e bool success IWizardStep _currentStep .NextStep if success if Stepindex - 1 Stepindex LoadWizardStep summary Move to the previous step summary protected void btnPrevious_Click object sender EventArgs e if Stepindex 0 Stepindex-- LoadWizardStep script html xmlns http 1999 xhtml head id Head1 runat server style type text css html font 14px Georgia Serif fieldset display block width 600px padding 20px margin 10px style title Wizard title From the Library of Wow eBook Dynamically Loading User Controls 335 head body form id form1 runat server div asp Label id lblStepNumber Runat server fieldset legend asp Literal ID ltlStep runat server legend asp PlaceHolder id plhWizardStep Runat server fieldset asp Button id btnPrevious Text lt Previous CausesValidation false OnClick btnPrevious_Click Runat server asp Button id btnNext Text Next gt OnClick btnNext_Click Runat server div form body html 7 The list of wizard steps is created in the Page_Load method. The path to each wizard step User control is added to a collection of wizard steps. The Stepindex property represents the index of the wizard step to display. The value of this property is stored in ViewState so that the value is available across multiple page requests. The current wizard step is loaded by the LoadWizardStep method. This method uses the Stepindex to grab the path to the current wizard step. Next it uses the method to actually load the wizard step User control. After the LoadWizardStep method loads the current wizard step it calls the control s LoadStep method and initializes the control. From the Library of Wow eBook 336 CHAPTER 7 Creating Custom Controls with User Controls The page also contains a Previous and Next button. When you click the Previous button the .
đang nạp các trang xem trước