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?

Recommended Answers

All 3 Replies

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?

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.