Converting HTML files to User Controls

B

Ben Amada

Hello,

A partner is going to be creating some HTML files that I plan on converting
to user controls (UC) and dynamically load at runtime. I'm guessing Visual
Studio doesn't come with some utililty to convert HTML files to UCs? IOW,
I'll have to manually convert each HTML file to a UC? I've never used user
controls before, so I'm wondering what I need to add and remove to each UC
(or HTML file) to make this work. For instance, I suppose I will need to
add an ASP.NET page directive to each UC and remove the <HTML>, <HEAD> and
<BODY> tags from each UC? What else do I need to add/remove? Is the
content of each ASCX just consist of the HTML that will be inserted into a
host ASPX page?

Also, I plan on adding some ASP.NET server controls (Labels, Image controls,
etc.) to the UC. Do I need to add a <Form runat="server"> tag to the ASCX
file if I'm going to be doing this? Lastly, since I'll be loading one of
these UCs dynamically, what do I put in the host ASPX file where the UC will
be loaded ... a placeholder? Or is there a less generic control I can add
to the host ASPX file - something like <asp:Control>?

Many questions :) Any answers are appreciated!
Thanks/Ben
 
K

Karl Seguin

Best thing to do would be to create a ASP.Net page, then create a new user
control and drop it on the page. It should give you some insight on what
you have to do.

There's no hard rule for what an uc contains, but you are right, typically
the enclosing page contains the <html><head>....</head><body><form
runat="server">...</form></body></html> and often times more. So you'll
likely not want that in your UC. Also the uc makes use of a @Control
directive, not @Page directive. As I said, you normally put the form
runat="Server" in the page, and put the user control within the form - that
way you can have multiple uc. Placeholders are good for storing controls.

Karl
 
B

Ben Amada

Karl said:
Best thing to do would be to create a ASP.Net page, then create a new user
control and drop it on the page. It should give you some insight on what
you have to do.

There's no hard rule for what an uc contains, but you are right, typically
the enclosing page contains the <html><head>....</head><body><form
runat="server">...</form></body></html> and often times more. So you'll
likely not want that in your UC. Also the uc makes use of a @Control
directive, not @Page directive. As I said, you normally put the form
runat="Server" in the page, and put the user control within the form -
that way you can have multiple uc. Placeholders are good for storing
controls.
Karl

Hi Karl,

Thanks for addressing my questions. As you suggest, I'll go ahead and
create a new web form, add a user control to it and see what code VS
generates.

Regards,
Ben
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top