Click to See Complete Forum and Search --> : help


abbe
June 5th, 2002, 05:01 AM
Please, help me !
I dinamicllly load my web user control (.ascx) in my .aspx page ,
but .asxc file containss a control textbox and the error is that the
textbox control must be in "form runat=server", but i want my
"form runat=server" to be in .aspx file.

pjpark
June 5th, 2002, 04:11 PM
You are correct, there should not be a "form runat=server" tag in your .ascx file.

After a little experimentation I would guess you are using Me.Controls.Add(LoadControl("MyControl.ascx")) or something similar. Instead, add the following line to the top of your script page: Protected MyForm As System.Web.UI.HtmlControls.HtmlForm where "MyForm" is the ID of the form on you aspx page. Then, the following should work: MyForm.Controls.Add(LoadControl("MyControl.ascx")) As an alternative, you could add your control dynamically to some other control inside the form, such as a panel or table.

BTW, I just looked at the MSDN web site and in their documentation they say to use Page.Controls.Add(...) which, in fact, does not work. Go figure.:confused:
Hope this helps!

pjp

pjpark
June 6th, 2002, 01:36 PM
The MS documentation has an example with the line Page.Controls.Add(C1)
This is technically correct but practically useless (sort of like the balloon/helicopter jokes) since the new control will be added at the end of the page after the closing form tag.

The accepted way to add user web controls at run time is to add them to an existing container control on the page such as a panel or table cell.

However, my code in the previous post will work as well if you just want throw your new controls in at the end of your web form.

HTH,

pjp