User Controls

M

Michael

Thank you for any help you can provide.

This is what I have:
index.aspx - contains nothing but a form with runat = server
header.ascx - contains asp image box
welcome.ascx - contains text
footer.ascx - contains text
login.ascx - contains asp/web labels and text boxes.

The index page is simply a container for all the user controls. The
header, footer, and welcome controls are always included. The login
control should only be included if the user has not logged in.

Everything runs perfectly if the login control in not included. When
the login control is included I get an error saying that the control
_ctl1_txtUser must reside between the form tags with runat set to
server. The actual control name is txtUser. I understand why the
name changes. What I don't understand is why it has to be in the form
tag. While investigating, I have read in other threads that controls
on user controls are rendered between the form tags of the parent
object. Can anyone offer any suggestions?
 
J

Jos

Michael said:
Thank you for any help you can provide.

This is what I have:
index.aspx - contains nothing but a form with runat = server
header.ascx - contains asp image box
welcome.ascx - contains text
footer.ascx - contains text
login.ascx - contains asp/web labels and text boxes.

The index page is simply a container for all the user controls. The
header, footer, and welcome controls are always included. The login
control should only be included if the user has not logged in.

Everything runs perfectly if the login control in not included. When
the login control is included I get an error saying that the control
_ctl1_txtUser must reside between the form tags with runat set to
server. The actual control name is txtUser. I understand why the
name changes. What I don't understand is why it has to be in the form
tag. While investigating, I have read in other threads that controls
on user controls are rendered between the form tags of the parent
object. Can anyone offer any suggestions?

Just move the <form runat="server"> and </form> tags in the body
of your index.aspx file, in such a way that the login user control
is included.
 
K

Keith

Michael,

I am assuming you are using the dynamic loading of the
form. This is where you add controls from the code. If
not completely ignore this post because it will confuse
you and go with the suggestion of Jos.

You should put a panel inside the <form></form> and add
all of your components to it. That way you can assure
that your components are added in the correct location.

Another suggestion (not sure if this one will work, but I
am assuming it will) would be to name your form tag and
add your items to the form tag. This again will assure
that you have you items added inside your form tags.

Something else to consider, You don't have to load these
controls dynamically. You can actually set their
visibility to true or false depending on if you would
like to display them.

I have no proof of this, but I think the dynamic loading
will be quicker because you are not loading all of the
objects every time you load the page. You are only
loading those that you specify based on if the user is
logged in or not.

There is a great example of this in the IBuySpy portal at
http://www.asp.net/Default.aspx?tabindex=5&tabid=42.
This has also evolved into http://dotnetnuke.com

Keith
 
S

S. Justin Gengo

Michael,

If you want to dynamically load the control to the page use a placeholder
control. The placeholder control simply shows where a dynamically loaded
control will appear on the page.

My website, www.aboutfortunate.com, uses a single page for the entire site
and switches it's content by dynamically loading various user controls into
a single placeholder.

If you'd like example code for doing so it's located in the site's code
library. Just click on the code library and then use the search box there to
search for: "dynamically load user control" or something similar and you'll
find the example.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
M

Michael

Thank you everyone for your suggestions.

Justin,

This is exactly what I was looking for. I have and index page and the
content (user control) will change with the users selections.

Thank you,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top