如何维护动态Radwizard或如何取消动态Radwizard

时间:2019-02-12 11:20:11

标签: c# asp.net telerik

我已经在用户控件中动态创建了radwizardsteps,可以随时更改,我正在动态创建另一个rad向导,其中包含4个步骤,每个步骤都包含一个动态表。现在的问题是,如果我再次请求另一个ajax来破坏第二个向导中的控件,那么我该如何维护这些控件,有人可以帮忙解决这个问题。

谢谢。

Usercontrol.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WizardUCDemo.ascx.cs" Inherits="WebUIFrameWork.UITemplate.WizardUCDemo" %>
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
<script type="text/javascript">
    function OnWizardstepChange() {
        var radManager = null;
        var stepIndex = $find("<%= wizardControl.ClientID %>").get_activeIndex();
        radManager = $find('<%=RadAjaxManager.GetCurrent(this.Page).ClientID%>');
        radManager.ajaxRequest("StepChange&"+stepIndex);
    }
</script>
</telerik:RadCodeBlock>
<telerik:RadWizard runat="server" RenderMode="Lightweight" ID="wizardControl" OnClientButtonClicked="OnWizardstepChange"
    DisplayProgressBar="false" ProgressBarPosition="Right" NavigationBarPosition="Right"
    NavigationButtonsPosition="Bottom" DisplayNavigationButtons="false">
</telerik:RadWizard>

Usercontrol.ascx.cs:

public void GenerateSteps()
{
 for (int i = 1; i < 5; i++)
 {
    Step = new RadWizardStep();
    Step.ID = "Step_" + i.ToString();
    Step.ClientIDMode = ClientIDMode.Static;

    Table = new Table();
    Table.ID = "Table" + i.ToString();
    Table.ClientIDMode = ClientIDMode.Static;
    newStep.Controls.Add(newTable);
    UIControlsWizard.WizardSteps.Add(newStep);
 }

aspx:

<telerik:RadCodeBlock runat="server">
<script type="text/javascript">
      function testMethod()
      {
          $find("<%= RadAjaxManager1.ClientID%>").ajaxRequest("demo")
      }
</script>
</telerik:RadCodeBlock>

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="wizardControl">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="wizardControl" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
</telerik:RadAjaxManager>
 <table>
        <tr>
            <td>
                <uc1:WizardUCDemo runat="server" ID="WizardUCDemo1" />
            </td>
            <td>
                <telerik:RadWizard runat="server" RenderMode="Lightweight" ID="RadWizard1" DisplayProgressBar="false"
                    ProgressBarPosition="Right" NavigationBarPosition="Right" NavigationButtonsPosition="Bottom"
                    DisplayNavigationButtons="false">
                </telerik:RadWizard>
            </td>
        </tr>
    </table>

aspx.cs:

 Table newTable;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WizardUCDemo.GenerateSteps();
        }
    }
public void reProduceWizardSteps()
{
   RadWizardStep newStep;
   for (int i = 1; i < 5; i++)
   {
       newStep = new RadWizardStep();
       newStep.ID = "newStep_" + i.ToString();
       newStep.ClientIDMode = ClientIDMode.Static;

       newTable = new Table();
       newTable.ID = "newTable" + i.ToString();
       newTable.ClientIDMode = ClientIDMode.Static;
       TableRow tRow = new TableRow();
       TableCell tCell = new TableCell();

       RadTextBox rtxtBoxNew = new RadTextBox();
       rtxtBoxNew.ID = "newTextBox_" + i.ToString();
       rtxtBoxNew.ClientIDMode = ClientIDMode.Static;
       rtxtBoxNew.ClientEvents.OnKeyPress = "testMethod";
       tCell.Controls.Add(rtxtBoxNew);
       tRow.Cells.Add(tCell);
       newTable.Controls.Add(tRow);
       newStep.Controls.Add(newTable);
       UIControlsWizard.WizardSteps.Add(newStep);
    }
}
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
   string commandText = e.Argument.ToString().Trim();
   var commandData = commandText.Split('&');
   commandText = commandData[0];
   switch (commandText)
   {
      case "StepChange":
          if (Convert.ToInt32(commandData[1])==1)
          {
              reProduceWizardSteps();
          }
              break;
   }
}

0 个答案:

没有答案