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. Advertising

  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. Advertising

  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. Advertising

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. Guest
    Replies:
    2
    Views:
    741
  2. Luis Ramírez.

    Can a webcontrol (webcontrol.dll) have a configuration file?

    Luis Ramírez., Jul 5, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    207
    Luis Ramírez
    Jul 6, 2004
  3. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    191
    Fabricio
    Sep 21, 2005
  4. Curt_C [MVP]

    Custom WebControl, custom property list

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

    Adding a WebControl to a WebControl

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

Share This Page