Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:35:23+00:00 2026-06-01T09:35:23+00:00

I have following asp.net code but it gives error when I change dropdown selected

  • 0

I have following asp.net code but it gives error when I change dropdown selected index:

<asp:UpdatePanel>
      <ContentTemplate>
        <asp:DropDownList ID="drp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drp_SelectedIndexChanged">
          <asp:ListItem Text="ABC" Value="ABC"></asp:ListItem>
          <asp:ListItem Text="DEF" Value="DEF"></asp:ListItem>
        </asp:DropDownList>
        <asp:Panel ID="pnl" runat="server">
        </asp:Panel>
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
      </ContentTemplate>
      <Triggers>
        <asp:PostBackTrigger ControlID="drp" />
        <asp:PostBackTrigger ControlID="Button1" />
      </Triggers>
    </asp:UpdatePanel>

Now made one function for create textbox and get textbox value into lable as following way

protected void drp_SelectedIndexChanged(object sender, EventArgs e)

{
  if (drp.SelectedIndex != 0)
  {
    ViewState["controls"] = true;
    CreateTextbox(drp.SelectedIndex);
  }

}

private void CreateTextbox(int Number)
{
  try
  {
    TextBox txtTextbox;
    Label lbltxtTextbox;
    for (int i = 0; i < Number; i++)
    {
      txtTextbox = new TextBox();
      txtTextbox.ID = "txtbox" + i;
      lbltxtTextbox = new Label();
      lbltxtTextbox.ID = "lbltxtbox" + i;
      pnl.Controls.Add(txtTextbox);
      pnl.Controls.Add(lbltxtTextbox);
    }
  }
  catch (Exception ex)
  {
  }
}

private void GetTextboxvalue(int Number)
{
  try
  {
    TextBox txtTextbox;
    Label lbltxtTextbox;
    for (int i = 0; i < Number; i++)
    {
      txtTextbox = (TextBox)pnl.FindControl("txtbox" + i);
      lbltxtTextbox = (Label)pnl.FindControl("lbltxtbox" + i);
      lbltxtTextbox.Text = txtTextbox.Text;
    }
  }
  catch (Exception ex)
  {
  }
}

protected void Button1_Click(object sender, EventArgs e)
{
  GetTextboxvalue(drp.SelectedIndex);
}
protected void Page_Load(object sender, EventArgs e)
{

  if (ViewState["controls"] != null)
    if (drp.SelectedIndex != 0)
    {
      CreateTextbox(drp.SelectedIndex);
    }



}

error is:

Multiple controls with the same ID 'txtbox0' were found. FindControl requires that controls have unique IDs.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:35:24+00:00Added an answer on June 1, 2026 at 9:35 am

    GUID

    Change the following line

    txtTextbox.ID = "txtbox" + sequentialId;
    

    to below line

    txtTextbox.ID = "txtbox" + Guid.NewGuid().ToString("N");
    

    You can follow the same approach in remaining places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anything I have tried didn't work. Currenly I have following code to change asp.net
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
I have the following code in my ASP.NET project public sealed class IoC {
I have the following code in a ASP.NET master page: <div id=hyperlinkimage><asp:HyperLink ID=SomeHyperLink runat=Server
I am using ASP.NET 3.5 with iTextSharp and I have the following code: var
This is a beginner level question for asp.net MVC I have the following code
In The Page_Load event of an ASP.NET USercontrol, I have the following Code: If
I have somebody elses code (C# ASP.Net) which contains the following query: string query
I have an ASP.NET web site with something similar to the following code: .aspx
I have the following html in my ASP.NET form. It represents a dropdown menu

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.