nesting webcontrols

G

GrantM

Hi,

I have created 2 controls i have created which inherit from webcontrol.


The first control is a Captcha, the second a form.
I would like to use the Captcha control in the form.

I am able to do this, but i cannot get this to Render where i want it to
render.
If i add it to the Control Collection, it will Render after the form.
If i don't add it to the Control Collection, i can get it to render where i
want, but it does not function properly.
The Init and PreRender methods of the Captcha control are not called if i
don't add it to the control collection.


Here is basically what my code looks like.
Any help on this will be greatly appreciated


1 public class CaptchaControl : WebControl, IPostBackDataHandler,
INamingContainer
2 {
3 protected override void Render(HtmlTextWriter Output)
4 {
5 //Render Control Here
6 }
7 }
8
9
10 public class FormControl : WebControl, IPostBackDataHandler,
INamingContainer
11 {
12 private CaptchaControl _captchaControl;
13
14 protected override void Render(HtmlTextWriter Output)
15 {
16 //Render start of control
17
18 _captchaControl.Render(Output); //Adding this makes the control
render twice
19
20 //Finish rendering control here
21 }
22
23 protected override void OnInit(EventArgs e)
24 {
25 base.OnInit(e);
26 if (Page != null)
27 {
28 Page.RegisterRequiresPostBack(this);
29 _captchaControl= new CaptchaControl();
30 Controls.Add(_captchaControl);
31 }
32 }
33 }
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top