Custom WebControl adding controls in the page

Discussion in 'ASP .Net Web Controls' started by Galore, Jun 3, 2004.

  1. Galore

    Galore Guest

    Hello,

    I'm writing a custom webcontrol, and I need to make it add input hidden
    controls within the tag form. Using Page.Controls.Add(control) isn't
    working, it's putting the control outside the tag form, then I can't
    access its data when I postback the webpage.

    Does anyone here can give me a clue about this?

    Thanks
     
    Galore, Jun 3, 2004
    #1
    1. Advertisements

  2. Don't use Page.Controls.Add() method. Depending on the work you shoudl
    accomplich I would do it the simplest way possible and implement a compound
    server control using CreateChildControls method and create your hidden
    field.

    You better check MSDN for that and get back for further assistance and we
    will tell you which methods you really need to override.

    And BTW. If your custom control won't rander anything visible (if it has
    only Hidden field), that better inherit from Control class instead of
    WebControl, because you don't need properties like Width, Height, Back...
    blah blah blah...

    --
    RobertK
    { Clever? No just smart. }


    "Galore" <> wrote in message
    news:...
    > Hello,
    >
    > I'm writing a custom webcontrol, and I need to make it add input hidden
    > controls within the tag form. Using Page.Controls.Add(control) isn't
    > working, it's putting the control outside the tag form, then I can't
    > access its data when I postback the webpage.
    >
    > Does anyone here can give me a clue about this?
    >
    > Thanks
     
    Robert Koritnik, Jun 3, 2004
    #2
    1. Advertisements

  3. Galore

    Galore Guest

    It's worked, thanks a lot!!!

    []'s

    Josema wrote:

    > Hi Galore,
    > Maybe this can help you...
    >
    > class Mycustomcontrol:System.web........WebControl
    > {
    > protected System.Web.UI.HtmlControls.HtmlInputHidden MyHidden;
    >
    > protected override OnInit(EventArgs e)
    > {
    > InitializeComponent();
    > }
    > private void InitializeComponent()
    > {
    > MyHidden=new System.Web.UI.HtmlControls.HtmlInputHidden MyHidden;
    > this.Controls.Add(MyHidden);
    > }
    > }
    >
    > this way you can add inside your control an input type hidden... then you only have to compile this webcontrol and add it into a WebForm.aspx
    >
    > Regards.
    > Josema.
    >
    >
    > ----- Galore wrote: -----
    >
    > Hello,
    >
    > I'm writing a custom webcontrol, and I need to make it add input hidden
    > controls within the tag form. Using Page.Controls.Add(control) isn't
    > working, it's putting the control outside the tag form, then I can't
    > access its data when I postback the webpage.
    >
    > Does anyone here can give me a clue about this?
    >
    > Thanks
    >
     
    Galore, Jun 3, 2004
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Ames

    Adding controls to Page.Controls collection

    Jeremy Ames, Mar 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,620
    Peter Blum
    Mar 5, 2004
  2. Guest
    Replies:
    2
    Views:
    901
  3. rodchar
    Replies:
    0
    Views:
    590
    rodchar
    Nov 26, 2007
  4. John Wallace

    Dynamically adding custom controls to page source file

    John Wallace, Aug 5, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    192
    John Wallace
    Aug 5, 2003
  5. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    326
    Fabricio
    Sep 21, 2005
  6. Guest
    Replies:
    1
    Views:
    186
    Guest
    Feb 17, 2005
  7. Curt_C [MVP]

    Custom WebControl, custom property list

    Curt_C [MVP], Sep 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    295
    Curt_C [MVP]
    Sep 1, 2005
  8. Steven

    Adding a WebControl to a WebControl

    Steven, Oct 13, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    196
    Steven
    Oct 13, 2008
Loading...