HI there,
I'm trying to create Drop Down Lists dynamically.
Two thing before we start:
1. Im working on a ContentPanel that is inside a master page
2. I cant add anything to the .aspx directly, so all the code must be inside the .aspx.cs

This is my code:

public void GenerateDDL(Page page){
   DropDownList element;
   element = new DropDownList();
   element.ID = "uxDropDownList";
   page.Controls.Add(element);
}

So far it worked just fine when it came to adding Labels, Images and Hyperlinks dynamically; but for some reason, when I try to add the DropDownList using the very same process I get the following error:

----->"Control 'uxDropDownList' of type 'DropDownList' must be placed inside a form tag with runat=server."

Any ideas how to make this work? Or how to add the server tag dynamically?

Edited 5 Years Ago by cavpollo: n/a

you 1st go to the html code of that form and then
see carefully that there should be one and only one from tag after body tag.
and it should be closed before that body tag
like this
<body>
<form ......>
</form>
</body>

you 1st go to the html code of that form and then
see carefully that there should be one and only one from tag after body tag.
and it should be closed before that body tag
like this
<body>
<form ......>
</form>
</body>

There is one and only one...


Any other guesses?

Edited 5 Years Ago by cavpollo: n/a

There is one and only one...


Any other guesses?

The controls were being added outside the closing html tag for some reason...

Solution:
Create a panel, and instead of adding controls to the page add them to that panel...

This question has already been answered. Start a new discussion instead.