This is a migrated thread and some comments may be shown as answers.

Duplicate id error

13 Answers 142 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
Hamid
Top achievements
Rank 1
Hamid asked on 30 Jul 2015, 12:30 PM

Hi

The following is my code.

 

<telerik:RadWizard runat="server" ID="RadWizard1" OnWizardStepCreated="RadWizard1_WizardStepCreated">
    <WizardSteps>
         <telerik:RadWizardStep ID="rwsStart" Title="شروع" StepType="Start">
         </telerik:RadWizardStep>
         <telerik:RadWizardStep ID="rwsEnd" Title="پایان" StepType="Finish">
         </telerik:RadWizardStep>
   </WizardSteps>
   <Localization Next="بعدی" Cancel="انصراف" Finish="پایان" Previous="قبلی" />
</telerik:RadWizard>
  
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick" Enabled="True">
</asp:Timer>

 When the timer post back page. There is an error to say:

Multiple controls with the same ID 'rwsEnd' were found. FindControl requires that controls have unique IDs.

13 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 31 Jul 2015, 05:30 AM
Hi,

It seems like the issue is caused by the custom how that you are using in the code behind because I could not replicate it by just using the mark up provided.

Regards,
Plamen
Telerik
0
Hamid
Top achievements
Rank 1
answered on 31 Jul 2015, 08:18 AM
protected void Page_Load(object sender, EventArgs e)
    {     
        if (!IsPostBack)
        {
            var myData = new DataAccess();
        myData.TesMasterIdFk = MasterId;
        myData.TesId = TestId;
        DataRow tRow = myData.TestDetailsReturn();
        lblTime.Text = tRow["TesTotalTimeLabel"].ToString();
 
        DataTable qTbl = new DataTable();
        myData.QueTestIdFk = TestId;
        myData.QueMasterIdFk = MasterId;
        qTbl = myData.QuestionsOfTestReturn();
 
        foreach (DataRow myRow in qTbl.Rows)
        {
            RadWizardStep step = new RadWizardStep();
            step.ID = "Q" + myRow["QueId"];
            step.Title = myRow["QueTitle"].ToString();
            RadWizard1.WizardSteps.AddAt(1, step);
        }
        }
    }
public void Timer1_Tick(object sender, EventArgs e)
    {
        RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps.Count-1;
        RadWizard1.Enabled = false;
    }
protected void RadWizard1_WizardStepCreated(object sender, WizardStepCreatedEventArgs e)
    {
        var myData = new DataAccess();
        DataTable qTbl = new DataTable();
        myData.QueTestIdFk = TestId;
        myData.QueMasterIdFk = MasterId;
        qTbl = myData.QuestionsOfTestReturn();
 
        foreach (DataRow myRow in qTbl.Rows)
        {
            if (e.RadWizardStep.ID == "Q" + myRow["QueId"])
            {
                Panel myPan = new Panel();
                myPan.CssClass = "tCss";
 
 
                //Add Label
                Label label = new Label();
                label.Text = myRow["QueTitle"].ToString();
                label.CssClass = "testLabel";
                myPan.Controls.Add(label);
 
                myData.ChoMasterIdFk = MasterId;
                myData.ChoTestIdFk = TestId;
                myData.ChoQuestionIdFk = Convert.ToInt64(myRow["QueId"].ToString());
                var choTbl = new DataTable();
                choTbl = myData.ChoisesOfQuestionReturn();
                foreach (DataRow myChoises in choTbl.Rows)
                {
                    //Add Choises
                    RadioButton radioBut = new RadioButton();
                    radioBut.Text = myChoises["ChoTitle"].ToString();
                    myPan.Controls.Add(radioBut);
                }
 
                e.RadWizardStep.Controls.Add(myPan);
            }
        }
    }
0
Hamid
Top achievements
Rank 1
answered on 01 Aug 2015, 05:04 PM

Hi

I'm waiting for an answer.

Please tell me what I can do?

0
Plamen
Telerik team
answered on 04 Aug 2015, 06:13 AM
Hello,

I have tested the same scenario in an isolated page but it worked correctly at my side. I am attaching my test page. Please review it and let me know what else to add in order to observe the same error.

Regards,
Plamen
Telerik
0
Hamid
Top achievements
Rank 1
answered on 17 Aug 2015, 03:20 PM

Hi

This is my project. Please tell me what's problem and it's solution.

Thanks.

 

<head runat="server">
    <title></title>
    <style type="text/css">
        .lblCss {
            display: block;
        }
 
        .panCss {
            font-family: tahoma;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:radscriptmanager ID="RadScriptManager1" runat="server"></telerik:radscriptmanager>
        <div>
            <telerik:radwizard runat="server" ID="RadWizard1" OnWizardStepCreated="RadWizard1_WizardStepCreated">
                <WizardSteps>
                    <telerik:RadWizardStep ID="rwsStart" Title="Start" StepType="Start">
                    </telerik:RadWizardStep>
                    <telerik:RadWizardStep ID="rwsEnd" Title="Finish" StepType="Finish">
                    </telerik:RadWizardStep>
                </WizardSteps>
            </telerik:radwizard>
        </div>
        <asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick" Enabled="True">
        </asp:Timer>
    </form>
</body>
</html>

 

protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           GetQuestionTable();
           GetChoicesTable();
           CreateSteps();
       }
   }
   protected void RadWizard1_WizardStepCreated(object sender, WizardStepCreatedEventArgs e)
   {
 
       DataTable tblQuestions = new DataTable();
       tblQuestions = GetQuestionTable();
 
       foreach (DataRow qRow in tblQuestions.Rows)
       {
           if (e.RadWizardStep.ID == "Q" + qRow["id"])
           {
               Panel containerPan = new Panel();
               containerPan.CssClass = "panCss";
 
               //Add Label
               Label label = new Label();
               label.Text = qRow["title"].ToString();
               label.CssClass = "lblCss";
               containerPan.Controls.Add(label);
 
               var tblCoices = new DataTable();
               tblCoices = GetChoicesTable();
 
               DataRow[] tbl =tblCoices.Select("questionIdFk=" + qRow["id"]);
               foreach (DataRow myChoises in tbl)
               {
                   //Add Choises
                   RadioButton radioBut = new RadioButton();
                   radioBut.ID = "Ch" + myChoises["id"];
                   radioBut.Text = myChoises["title"].ToString();
                   radioBut.AutoPostBack = true;
                   radioBut.GroupName = Guid.NewGuid().ToString();
                   //radioBut.CheckedChanged += radioButtons_CheckedChanged;
                   containerPan.Controls.Add(radioBut);
               }
 
               e.RadWizardStep.Controls.Add(containerPan);
           }
       }
   }
 
   public void Timer1_Tick(object sender, EventArgs e)
   {
       RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps.Count - 1;
       RadWizard1.Enabled = false;
   }
   private DataTable GetQuestionTable()
   {
       //Creating Question Table
       var tblQuestions = new DataTable();
       tblQuestions.Columns.Add("id");
       tblQuestions.Columns.Add("title");
 
       for (int i = 0; i < 10; i++)
       {
           DataRow questionRow = tblQuestions.NewRow();
           questionRow["id"] = i;
           questionRow["title"] = "Question " + i;
           tblQuestions.Rows.Add(questionRow);
       }
 
       return tblQuestions;
   }
   private DataTable GetChoicesTable()
   {
       //Creating Choices Table
       var tblChoices = new DataTable();
       tblChoices.Columns.Add("id");
       tblChoices.Columns.Add("title");
       tblChoices.Columns.Add("questionIdFk");
 
       int k = 1;
       for (int i = 0; i < 10; i++)
       {
           for (int j = 0; j < 4; j++)
           {
               DataRow rowChoices = tblChoices.NewRow();
               rowChoices["id"] = k;
               rowChoices["title"] = "Choice Number:  "+ (j+1);
               rowChoices["questionIdFk"] = i;
               tblChoices.Rows.Add(rowChoices);
               k++;
           }
       }
       return tblChoices;
   }
   private void CreateSteps()
   {
       //Creating Steps of Wizard
       var tblQuestions = new DataTable();
       tblQuestions = GetQuestionTable();
       foreach (DataRow qRow in tblQuestions.Rows)
       {
           RadWizardStep step = new RadWizardStep();
 
           step.ID = "Q" + qRow["id"];
           step.Title = qRow["title"].ToString();
           RadWizard1.WizardSteps.AddAt(1, step);
       }
   }

0
Hamid
Top achievements
Rank 1
answered on 18 Aug 2015, 12:15 PM

Please answer me.

It's important for me to solve this problem quickly.

0
Plamen
Telerik team
answered on 20 Aug 2015, 06:34 AM
Hello,

It seems that at some moment you are setting the same IDs to the wizard steps. Yet I have tested the issue at my side and it worked correctly. The issue may be coming from your custom DataSource. Would you please let me know what else should I add to the sample page I sent you to be able to replicate the issue and be more helpful with a possible solution.

Regards,
Plamen
Telerik
0
Hamid
Top achievements
Rank 1
answered on 20 Aug 2015, 07:39 AM

Hi

I wrote all my codes in my page, there ​are no other codes.

Please create project and test it.

0
Plamen
Telerik team
answered on 24 Aug 2015, 04:58 AM
Hi,

I have tested the issue once again but unfortunately could not replicate it once again. It seems that the issue is caused by your custom data that is pushing the same ids. Please try to replicate the issue without your custom DataBase and share the code so we could be more helpful.

Regards,
Plamen
Telerik
0
Hamid
Top achievements
Rank 1
answered on 24 Aug 2015, 06:24 AM

Here is my project.

https://onedrive.live.com/redir?resid=2673FD1F430E2666!937&authkey=!AHaU5u6TGQcVcUs&ithint=file%2crar

There is no other datasource here. If you test it you can see the error.​

0
Plamen
Telerik team
answered on 25 Aug 2015, 08:26 AM
Hello,

I have inspected code that you provided and noticed that the issue is caused by the fact that you ahve added two of the steps from the mark up. 

In cases when the steps are going to be added and removed we recommend adding all the steps from the code behind. Here instead of mixing mark up and code behind. here is the code that worked correctly at my side:
private void CreateSteps()
   {
       RadWizardStep stepStart = new RadWizardStep();
 
       stepStart.ID = "rwsStart";
       RadWizard1.WizardSteps.AddAt(0, stepStart);
       //Creating Steps of Wizard
       var tblQuestions = new DataTable();
       tblQuestions = GetQuestionTable();
       foreach (DataRow qRow in tblQuestions.Rows)
       {
           RadWizardStep step = new RadWizardStep();
 
           step.ID = "Q" + qRow["id"];
           step.Title = qRow["title"].ToString();
           RadWizard1.WizardSteps.AddAt(1, step);
       }
       RadWizardStep stepEnd = new RadWizardStep();
 
       stepEnd.ID = "rwsEnd";
       RadWizard1.WizardSteps.AddAt(RadWizard1.WizardSteps.Count, stepEnd);
   }
<telerik:RadWizard runat="server" ID="RadWizard1" OnWizardStepCreated="RadWizard1_WizardStepCreated">
 
          </telerik:RadWizard>

Hope this will help you solve the issue.

Regards,
Plamen
Telerik
0
Hamid
Top achievements
Rank 1
answered on 25 Aug 2015, 11:41 AM

Hi

The reason I'm trying to both markup and code behind to create wizard steps is I want to add some information in start step and add chard to final step to show test result. In other words first and last wizards are so complex and creating them dynamically need hundred lines of codes.

Also there is a problem with your solution; when timer refreshes page all the property of wizards lost, for example title of them.

0
Plamen
Telerik team
answered on 28 Aug 2015, 07:18 AM
Hi Hamid,

If you want to define the steps statically you will have to remove their static ids which leading to the error observed.

If you prefer to go for a dynamic steps we recommend setting the title and other properties different from id in the WizardStepCreated event so they are persisted correctly.
Here is the sample code that I used:
if (e.RadWizardStep.ID == "rwsStart" )
     {
         e.RadWizardStep.Title = "Start";
     }

Hope this will explain the issue.

Regards,
Plamen
Telerik
Tags
Wizard
Asked by
Hamid
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Hamid
Top achievements
Rank 1
Share this question
or