Riki
11/19/2007 12:05:00 PM
Beatrix wrote:
> Thankyou that worked. Can U please explain, why textbox is not
> working like label? What is the meaning of this mess with htmlform
> and findcontrol?
>
> If I put all my controls in this htmlform, like radiobuttons, etc it
> will always work?
A textbox has to be inside a form tag with the runat="server" attribute.
You can test this out by adding a textbox to your page in the editor, but
placing it outside the form tag.
You will get the same error as you did before.
The problem with your previous code was that you use:
Controls.Add(txtYourAnswer)
This is the same as:
Page.Controls.Add(txtYourAnswer)
This means that your textbox will be added AFTER all the other controls,
i.e. after the form tag (even after the closing body tag).
Which is causing the error.
When you use f.Controls.Add(myTextbox), it will be added after all the
controls INSIDE the form tag.
Hope this helps you understand.
--
Riki