|
-
June 5th, 2002, 05:01 AM
#1
help
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.
-
June 5th, 2002, 04:11 PM
#2
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
Code:
Me.Controls.Add(LoadControl("MyControl.ascx"))
or something similar. Instead, add the following line to the top of your script page:
Code:
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:
Code:
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.
Hope this helps!
pjp
Last edited by pjpark; June 5th, 2002 at 04:18 PM.
-
June 6th, 2002, 01:36 PM
#3
Update
The MS documentation has an example with the line
Code:
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|