Creating Custom Controls

R

Ryan Wade

I created a custom control that works great if you drop it
on the web form. If I dynamically create it by

this.Response.Write("<td>");
this.Response.Write("<uc1:EnterCase id=\"cEnterCase\"
runat=\"server\">");
this.Response.Write("</uc1:EnterCase>");
this.Response.Write("</td>");

The control doesn't show up on the web form. I have to
dynamically create it like this because i build my form at
runtime. Is this the right way to do it? At the top of
the html I also have

<%@ Register TagPrefix="uc1" TagName="EnterCase"
Src="EnterCase.ascx" %>

Any help would be appreciated. Thanks

Ryan
 
W

William F. Robertson, Jr.

You are not "dynamically" creating your control by writing it to
Response.Write. Response.Write will send that exact instruction to the
client browser. IE (or any other browser) does not recognize the
"<uc1:EnterCase..." tag.

To achieve what you are looking for you probably want to use a placeholder
control and drop that on the form. Then in code behind add the dynamically
created control to the placeholder control through the Controls collection.

For example:

PlaceHolder ph = new PlaceHolder();
EnterCase dynamicControl = new EnterCase();
//set the properties you want to set including ID
ph.Controls.Add( dynamicControl );

HTH,

bill
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top