Control 'X' of type 'RadioButton' must be placed inside a form tag with runat=server.

Discussion in 'ASP .Net' started by Tom wilson, Feb 8, 2005.

  1. Tom wilson

    Tom wilson Guest

    I'm trying to create dynamic controls in ASP.Net. It's driving me
    nuts. I keep getting the error:

    Control '16' of type 'RadioButton' must be placed inside a form tag
    with runat=server.

    Dim Place1 As New PlaceHolder
    Controls.Add(Place1)
    For y = 1 To Choices.RecordCount
    Choices.MoveTo(y)
    Dim Radio As New RadioButton
    Radio.ID = choices.ID
    Radio.Text = choices.ChoiceText
    Radio.GroupName = Q.ID
    Place1.Controls.Add(Radio)

    If I do Controls.Add(Radio) I get the above error. So I created a
    placeholder in design view (there's nothing there since all page
    content is dynamic). It added the radios but at the bottom of the
    form. So I modified the code to dynamically create the placeholder
    (as above). I STILL get this error.

    Do I have to do a:
    response.write("<FORM etc etc... runat=server>")
    before every checbox creation?

    Why doesn't it add the tags itself while its creating the controls?

    How do I add a control without getting that needless error at every
    turn?

    Thanks!
    Tom wilson, Feb 8, 2005
    #1
    1. Advertising

  2. Tom wilson

    fd123456 Guest

    Hi Tom,

    Try this instead of Controls.Add(Place1):

    Me.FindControl("Form1").Controls.Add(Place1)

    (provided your form is called Form1, obviously, but that's what it's
    called by default).

    You were adding the radiobuttons in the Page controls, but outside of
    the Form controls.

    Also note that "Me." is only here for demonstration purposes. You can
    omit it, it's implicit.

    HTH,

    Michel

    Tom wilson <> wrote in message news:<>...
    > I'm trying to create dynamic controls in ASP.Net. It's driving me
    > nuts. I keep getting the error:
    >
    > Control '16' of type 'RadioButton' must be placed inside a form tag
    > with runat=server.
    >
    > Dim Place1 As New PlaceHolder
    > Controls.Add(Place1)
    > For y = 1 To Choices.RecordCount
    > Choices.MoveTo(y)
    > Dim Radio As New RadioButton
    > Radio.ID = choices.ID
    > Radio.Text = choices.ChoiceText
    > Radio.GroupName = Q.ID
    > Place1.Controls.Add(Radio)
    >
    > If I do Controls.Add(Radio) I get the above error. So I created a
    > placeholder in design view (there's nothing there since all page
    > content is dynamic). It added the radios but at the bottom of the
    > form. So I modified the code to dynamically create the placeholder
    > (as above). I STILL get this error.
    >
    > Do I have to do a:
    > response.write("<FORM etc etc... runat=server>")
    > before every checbox creation?
    >
    > Why doesn't it add the tags itself while its creating the controls?
    >
    > How do I add a control without getting that needless error at every
    > turn?
    >
    > Thanks!
    fd123456, Feb 9, 2005
    #2
    1. Advertising

  3. Tom wilson

    Tom wilson Guest

    When I add that line I get "Object reference not set to..." I've
    tried it on its own page with nothing else but this:

    Dim Place1 as new Placeholder
    me.FindForm("TestForm").Controls.Add(Place1)

    Same result. I have discovered that I can add a placeholder in design
    view and it will accept control additions. I guess the whole problem
    is that I cannot create a placeholder dynamically within the form
    tags. I don't know why something so simple has to be so complicated.



    On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:

    >Hi Tom,
    >
    >Try this instead of Controls.Add(Place1):
    >
    >Me.FindControl("Form1").Controls.Add(Place1)
    >
    >(provided your form is called Form1, obviously, but that's what it's
    >called by default).
    >
    >You were adding the radiobuttons in the Page controls, but outside of
    >the Form controls.
    >
    >Also note that "Me." is only here for demonstration purposes. You can
    >omit it, it's implicit.
    >
    >HTH,
    >
    >Michel
    >
    >Tom wilson <> wrote in message news:<>...
    >> I'm trying to create dynamic controls in ASP.Net. It's driving me
    >> nuts. I keep getting the error:
    >>
    >> Control '16' of type 'RadioButton' must be placed inside a form tag
    >> with runat=server.
    >>
    >> Dim Place1 As New PlaceHolder
    >> Controls.Add(Place1)
    >> For y = 1 To Choices.RecordCount
    >> Choices.MoveTo(y)
    >> Dim Radio As New RadioButton
    >> Radio.ID = choices.ID
    >> Radio.Text = choices.ChoiceText
    >> Radio.GroupName = Q.ID
    >> Place1.Controls.Add(Radio)
    >>
    >> If I do Controls.Add(Radio) I get the above error. So I created a
    >> placeholder in design view (there's nothing there since all page
    >> content is dynamic). It added the radios but at the bottom of the
    >> form. So I modified the code to dynamically create the placeholder
    >> (as above). I STILL get this error.
    >>
    >> Do I have to do a:
    >> response.write("<FORM etc etc... runat=server>")
    >> before every checbox creation?
    >>
    >> Why doesn't it add the tags itself while its creating the controls?
    >>
    >> How do I add a control without getting that needless error at every
    >> turn?
    >>
    >> Thanks!
    Tom wilson, Feb 9, 2005
    #3
  4. Couple things.

    1. What is your page derived from to have a FindForm method?
    2. Your form is probably called frmTestForm.

    me.FindControl( "frmTestForm" ).Controls.Add( Place1 )

    It really isn't that complicated; it is simply a matter of learning the
    framework. Although I do wish MS would have exposed the internal Form
    property they have. Perhaps this will be modified in 2.0.

    bill

    "Tom wilson" <> wrote in message
    news:...
    > When I add that line I get "Object reference not set to..." I've
    > tried it on its own page with nothing else but this:
    >
    > Dim Place1 as new Placeholder
    > me.FindForm("TestForm").Controls.Add(Place1)
    >
    > Same result. I have discovered that I can add a placeholder in design
    > view and it will accept control additions. I guess the whole problem
    > is that I cannot create a placeholder dynamically within the form
    > tags. I don't know why something so simple has to be so complicated.
    >
    >
    >
    > On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:
    >
    > >Hi Tom,
    > >
    > >Try this instead of Controls.Add(Place1):
    > >
    > >Me.FindControl("Form1").Controls.Add(Place1)
    > >
    > >(provided your form is called Form1, obviously, but that's what it's
    > >called by default).
    > >
    > >You were adding the radiobuttons in the Page controls, but outside of
    > >the Form controls.
    > >
    > >Also note that "Me." is only here for demonstration purposes. You can
    > >omit it, it's implicit.
    > >
    > >HTH,
    > >
    > >Michel
    > >
    > >Tom wilson <> wrote in message

    news:<>...
    > >> I'm trying to create dynamic controls in ASP.Net. It's driving me
    > >> nuts. I keep getting the error:
    > >>
    > >> Control '16' of type 'RadioButton' must be placed inside a form tag
    > >> with runat=server.
    > >>
    > >> Dim Place1 As New PlaceHolder
    > >> Controls.Add(Place1)
    > >> For y = 1 To Choices.RecordCount
    > >> Choices.MoveTo(y)
    > >> Dim Radio As New RadioButton
    > >> Radio.ID = choices.ID
    > >> Radio.Text = choices.ChoiceText
    > >> Radio.GroupName = Q.ID
    > >> Place1.Controls.Add(Radio)
    > >>
    > >> If I do Controls.Add(Radio) I get the above error. So I created a
    > >> placeholder in design view (there's nothing there since all page
    > >> content is dynamic). It added the radios but at the bottom of the
    > >> form. So I modified the code to dynamically create the placeholder
    > >> (as above). I STILL get this error.
    > >>
    > >> Do I have to do a:
    > >> response.write("<FORM etc etc... runat=server>")
    > >> before every checbox creation?
    > >>
    > >> Why doesn't it add the tags itself while its creating the controls?
    > >>
    > >> How do I add a control without getting that needless error at every
    > >> turn?
    > >>
    > >> Thanks!

    >
    William F. Robertson, Jr., Feb 9, 2005
    #4
  5. Tom wilson

    Tom wilson Guest

    1 - How do I find that out? The Class is called "TestForm". It
    appears to inherit from "MyApp.TestForm". Is that what I need?


    Not complicated? This is a re-write of a survey application
    originally done in asp. For that method, it was as simple as one line
    of HTML to create a textbox and response.write the text/html. With
    this I have to:

    1 - Manually add a placeholder to the empty form. I can't create one
    dynamically, everyt method I've tried fails.

    2 - Create a set of control arrays for each type of control; checkbox,
    radio, etc.

    3 - Redim Preserve each array as the number of controls increases as
    they are created. I hope 500 radios don't eat too much memory.

    4 - Create the control, takes about 5 lines of code not including the
    array tracking.

    5 - Add the newly created control to the placeholder.

    ....and everything must be a control. Text? HTML? They have to be
    defined as LiteralControl(s) and added in sequence. I remember when
    it was called "response.write" but if I do that, all the text is at
    the top of the page and the controls underneath because response.write
    doesn't add to a placeholder. I swear if I have to do tables my head
    will explode.

    Yes, it's that complicated.

    Sorry about the rant, it's been 3 days at this with little progress.
    I do very much appreciate your input.




    On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
    <> wrote:

    >Couple things.
    >
    >1. What is your page derived from to have a FindForm method?
    >2. Your form is probably called frmTestForm.
    >
    >me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
    >
    >It really isn't that complicated; it is simply a matter of learning the
    >framework. Although I do wish MS would have exposed the internal Form
    >property they have. Perhaps this will be modified in 2.0.
    >
    >bill
    >
    >"Tom wilson" <> wrote in message
    >news:...
    >> When I add that line I get "Object reference not set to..." I've
    >> tried it on its own page with nothing else but this:
    >>
    >> Dim Place1 as new Placeholder
    >> me.FindForm("TestForm").Controls.Add(Place1)
    >>
    >> Same result. I have discovered that I can add a placeholder in design
    >> view and it will accept control additions. I guess the whole problem
    >> is that I cannot create a placeholder dynamically within the form
    >> tags. I don't know why something so simple has to be so complicated.
    >>
    >>
    >>
    >> On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:
    >>
    >> >Hi Tom,
    >> >
    >> >Try this instead of Controls.Add(Place1):
    >> >
    >> >Me.FindControl("Form1").Controls.Add(Place1)
    >> >
    >> >(provided your form is called Form1, obviously, but that's what it's
    >> >called by default).
    >> >
    >> >You were adding the radiobuttons in the Page controls, but outside of
    >> >the Form controls.
    >> >
    >> >Also note that "Me." is only here for demonstration purposes. You can
    >> >omit it, it's implicit.
    >> >
    >> >HTH,
    >> >
    >> >Michel
    >> >
    >> >Tom wilson <> wrote in message

    >news:<>...
    >> >> I'm trying to create dynamic controls in ASP.Net. It's driving me
    >> >> nuts. I keep getting the error:
    >> >>
    >> >> Control '16' of type 'RadioButton' must be placed inside a form tag
    >> >> with runat=server.
    >> >>
    >> >> Dim Place1 As New PlaceHolder
    >> >> Controls.Add(Place1)
    >> >> For y = 1 To Choices.RecordCount
    >> >> Choices.MoveTo(y)
    >> >> Dim Radio As New RadioButton
    >> >> Radio.ID = choices.ID
    >> >> Radio.Text = choices.ChoiceText
    >> >> Radio.GroupName = Q.ID
    >> >> Place1.Controls.Add(Radio)
    >> >>
    >> >> If I do Controls.Add(Radio) I get the above error. So I created a
    >> >> placeholder in design view (there's nothing there since all page
    >> >> content is dynamic). It added the radios but at the bottom of the
    >> >> form. So I modified the code to dynamically create the placeholder
    >> >> (as above). I STILL get this error.
    >> >>
    >> >> Do I have to do a:
    >> >> response.write("<FORM etc etc... runat=server>")
    >> >> before every checbox creation?
    >> >>
    >> >> Why doesn't it add the tags itself while its creating the controls?
    >> >>
    >> >> How do I add a control without getting that needless error at every
    >> >> turn?
    >> >>
    >> >> Thanks!

    >>

    >
    Tom wilson, Feb 9, 2005
    #5
  6. 1 - look at the aspx side of the page.

    You will see the form element.

    <form runat="server" id="myForm">

    You can get this control by typing
    Form = Page.FindControl( "myForm" );

    Notice the parameter to FindControl is the ID of the control. If ID isn't
    there, then assign it one.

    ASP.NET is a completely different way of html generation. You really can't
    think of things such as, "in asp I would just do document.write, etc." You
    must think of terms of controls.

    I really don't know enough about your requirements to tell you how and what
    you should be doing, but I wish you the best of luck. There are several
    ways to accomplish what you are trying to do.

    Is the entire page dynamic? What determines the content? How much state
    information should be maintained.

    bill

    You can always access the Request.Forms("txtName") and get the posted values
    without worry about setting up control trees.
    Also, if you really like the asp rendering module, you can always override
    the Page.Render method and write out the html using Response.Write.
    Although I don't think anyone on this board would recommend that approach.




    "Tom wilson" <> wrote in message
    news:...
    > 1 - How do I find that out? The Class is called "TestForm". It
    > appears to inherit from "MyApp.TestForm". Is that what I need?
    >
    >
    > Not complicated? This is a re-write of a survey application
    > originally done in asp. For that method, it was as simple as one line
    > of HTML to create a textbox and response.write the text/html. With
    > this I have to:
    >
    > 1 - Manually add a placeholder to the empty form. I can't create one
    > dynamically, everyt method I've tried fails.
    >
    > 2 - Create a set of control arrays for each type of control; checkbox,
    > radio, etc.
    >
    > 3 - Redim Preserve each array as the number of controls increases as
    > they are created. I hope 500 radios don't eat too much memory.
    >
    > 4 - Create the control, takes about 5 lines of code not including the
    > array tracking.
    >
    > 5 - Add the newly created control to the placeholder.
    >
    > ...and everything must be a control. Text? HTML? They have to be
    > defined as LiteralControl(s) and added in sequence. I remember when
    > it was called "response.write" but if I do that, all the text is at
    > the top of the page and the controls underneath because response.write
    > doesn't add to a placeholder. I swear if I have to do tables my head
    > will explode.
    >
    > Yes, it's that complicated.
    >
    > Sorry about the rant, it's been 3 days at this with little progress.
    > I do very much appreciate your input.
    >
    >
    >
    >
    > On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
    > <> wrote:
    >
    > >Couple things.
    > >
    > >1. What is your page derived from to have a FindForm method?
    > >2. Your form is probably called frmTestForm.
    > >
    > >me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
    > >
    > >It really isn't that complicated; it is simply a matter of learning the
    > >framework. Although I do wish MS would have exposed the internal Form
    > >property they have. Perhaps this will be modified in 2.0.
    > >
    > >bill
    > >
    > >"Tom wilson" <> wrote in message
    > >news:...
    > >> When I add that line I get "Object reference not set to..." I've
    > >> tried it on its own page with nothing else but this:
    > >>
    > >> Dim Place1 as new Placeholder
    > >> me.FindForm("TestForm").Controls.Add(Place1)
    > >>
    > >> Same result. I have discovered that I can add a placeholder in design
    > >> view and it will accept control additions. I guess the whole problem
    > >> is that I cannot create a placeholder dynamically within the form
    > >> tags. I don't know why something so simple has to be so complicated.
    > >>
    > >>
    > >>
    > >> On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:
    > >>
    > >> >Hi Tom,
    > >> >
    > >> >Try this instead of Controls.Add(Place1):
    > >> >
    > >> >Me.FindControl("Form1").Controls.Add(Place1)
    > >> >
    > >> >(provided your form is called Form1, obviously, but that's what it's
    > >> >called by default).
    > >> >
    > >> >You were adding the radiobuttons in the Page controls, but outside of
    > >> >the Form controls.
    > >> >
    > >> >Also note that "Me." is only here for demonstration purposes. You can
    > >> >omit it, it's implicit.
    > >> >
    > >> >HTH,
    > >> >
    > >> >Michel
    > >> >
    > >> >Tom wilson <> wrote in message

    > >news:<>...
    > >> >> I'm trying to create dynamic controls in ASP.Net. It's driving me
    > >> >> nuts. I keep getting the error:
    > >> >>
    > >> >> Control '16' of type 'RadioButton' must be placed inside a form tag
    > >> >> with runat=server.
    > >> >>
    > >> >> Dim Place1 As New PlaceHolder
    > >> >> Controls.Add(Place1)
    > >> >> For y = 1 To Choices.RecordCount
    > >> >> Choices.MoveTo(y)
    > >> >> Dim Radio As New RadioButton
    > >> >> Radio.ID = choices.ID
    > >> >> Radio.Text = choices.ChoiceText
    > >> >> Radio.GroupName = Q.ID
    > >> >> Place1.Controls.Add(Radio)
    > >> >>
    > >> >> If I do Controls.Add(Radio) I get the above error. So I created a
    > >> >> placeholder in design view (there's nothing there since all page
    > >> >> content is dynamic). It added the radios but at the bottom of the
    > >> >> form. So I modified the code to dynamically create the placeholder
    > >> >> (as above). I STILL get this error.
    > >> >>
    > >> >> Do I have to do a:
    > >> >> response.write("<FORM etc etc... runat=server>")
    > >> >> before every checbox creation?
    > >> >>
    > >> >> Why doesn't it add the tags itself while its creating the controls?
    > >> >>
    > >> >> How do I add a control without getting that needless error at every
    > >> >> turn?
    > >> >>
    > >> >> Thanks!
    > >>

    > >

    >
    William F. Robertson, Jr., Feb 9, 2005
    #6
  7. Tom wilson

    Tom wilson Guest

    Ok, I have the page working using a single static placeholder.
    That'll do the job. 100% of the content is retrieved from a SQL
    Server database and everything down to the text is generated
    dynamcially. I'm just fighting with the session object now. :)

    I appreciate your help. Thanks!


    On Wed, 9 Feb 2005 13:50:16 -0600, "William F. Robertson, Jr."
    <> wrote:

    >1 - look at the aspx side of the page.
    >
    >You will see the form element.
    >
    ><form runat="server" id="myForm">
    >
    >You can get this control by typing
    >Form = Page.FindControl( "myForm" );
    >
    >Notice the parameter to FindControl is the ID of the control. If ID isn't
    >there, then assign it one.
    >
    >ASP.NET is a completely different way of html generation. You really can't
    >think of things such as, "in asp I would just do document.write, etc." You
    >must think of terms of controls.
    >
    >I really don't know enough about your requirements to tell you how and what
    >you should be doing, but I wish you the best of luck. There are several
    >ways to accomplish what you are trying to do.
    >
    >Is the entire page dynamic? What determines the content? How much state
    >information should be maintained.
    >
    >bill
    >
    >You can always access the Request.Forms("txtName") and get the posted values
    >without worry about setting up control trees.
    >Also, if you really like the asp rendering module, you can always override
    >the Page.Render method and write out the html using Response.Write.
    >Although I don't think anyone on this board would recommend that approach.
    >
    >
    >
    >
    >"Tom wilson" <> wrote in message
    >news:...
    >> 1 - How do I find that out? The Class is called "TestForm". It
    >> appears to inherit from "MyApp.TestForm". Is that what I need?
    >>
    >>
    >> Not complicated? This is a re-write of a survey application
    >> originally done in asp. For that method, it was as simple as one line
    >> of HTML to create a textbox and response.write the text/html. With
    >> this I have to:
    >>
    >> 1 - Manually add a placeholder to the empty form. I can't create one
    >> dynamically, everyt method I've tried fails.
    >>
    >> 2 - Create a set of control arrays for each type of control; checkbox,
    >> radio, etc.
    >>
    >> 3 - Redim Preserve each array as the number of controls increases as
    >> they are created. I hope 500 radios don't eat too much memory.
    >>
    >> 4 - Create the control, takes about 5 lines of code not including the
    >> array tracking.
    >>
    >> 5 - Add the newly created control to the placeholder.
    >>
    >> ...and everything must be a control. Text? HTML? They have to be
    >> defined as LiteralControl(s) and added in sequence. I remember when
    >> it was called "response.write" but if I do that, all the text is at
    >> the top of the page and the controls underneath because response.write
    >> doesn't add to a placeholder. I swear if I have to do tables my head
    >> will explode.
    >>
    >> Yes, it's that complicated.
    >>
    >> Sorry about the rant, it's been 3 days at this with little progress.
    >> I do very much appreciate your input.
    >>
    >>
    >>
    >>
    >> On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
    >> <> wrote:
    >>
    >> >Couple things.
    >> >
    >> >1. What is your page derived from to have a FindForm method?
    >> >2. Your form is probably called frmTestForm.
    >> >
    >> >me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
    >> >
    >> >It really isn't that complicated; it is simply a matter of learning the
    >> >framework. Although I do wish MS would have exposed the internal Form
    >> >property they have. Perhaps this will be modified in 2.0.
    >> >
    >> >bill
    >> >
    >> >"Tom wilson" <> wrote in message
    >> >news:...
    >> >> When I add that line I get "Object reference not set to..." I've
    >> >> tried it on its own page with nothing else but this:
    >> >>
    >> >> Dim Place1 as new Placeholder
    >> >> me.FindForm("TestForm").Controls.Add(Place1)
    >> >>
    >> >> Same result. I have discovered that I can add a placeholder in design
    >> >> view and it will accept control additions. I guess the whole problem
    >> >> is that I cannot create a placeholder dynamically within the form
    >> >> tags. I don't know why something so simple has to be so complicated.
    >> >>
    >> >>
    >> >>
    >> >> On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:
    >> >>
    >> >> >Hi Tom,
    >> >> >
    >> >> >Try this instead of Controls.Add(Place1):
    >> >> >
    >> >> >Me.FindControl("Form1").Controls.Add(Place1)
    >> >> >
    >> >> >(provided your form is called Form1, obviously, but that's what it's
    >> >> >called by default).
    >> >> >
    >> >> >You were adding the radiobuttons in the Page controls, but outside of
    >> >> >the Form controls.
    >> >> >
    >> >> >Also note that "Me." is only here for demonstration purposes. You can
    >> >> >omit it, it's implicit.
    >> >> >
    >> >> >HTH,
    >> >> >
    >> >> >Michel
    >> >> >
    >> >> >Tom wilson <> wrote in message
    >> >news:<>...
    >> >> >> I'm trying to create dynamic controls in ASP.Net. It's driving me
    >> >> >> nuts. I keep getting the error:
    >> >> >>
    >> >> >> Control '16' of type 'RadioButton' must be placed inside a form tag
    >> >> >> with runat=server.
    >> >> >>
    >> >> >> Dim Place1 As New PlaceHolder
    >> >> >> Controls.Add(Place1)
    >> >> >> For y = 1 To Choices.RecordCount
    >> >> >> Choices.MoveTo(y)
    >> >> >> Dim Radio As New RadioButton
    >> >> >> Radio.ID = choices.ID
    >> >> >> Radio.Text = choices.ChoiceText
    >> >> >> Radio.GroupName = Q.ID
    >> >> >> Place1.Controls.Add(Radio)
    >> >> >>
    >> >> >> If I do Controls.Add(Radio) I get the above error. So I created a
    >> >> >> placeholder in design view (there's nothing there since all page
    >> >> >> content is dynamic). It added the radios but at the bottom of the
    >> >> >> form. So I modified the code to dynamically create the placeholder
    >> >> >> (as above). I STILL get this error.
    >> >> >>
    >> >> >> Do I have to do a:
    >> >> >> response.write("<FORM etc etc... runat=server>")
    >> >> >> before every checbox creation?
    >> >> >>
    >> >> >> Why doesn't it add the tags itself while its creating the controls?
    >> >> >>
    >> >> >> How do I add a control without getting that needless error at every
    >> >> >> turn?
    >> >> >>
    >> >> >> Thanks!
    >> >>
    >> >

    >>

    >
    Tom wilson, Feb 10, 2005
    #7
  8. Glad to here you got it "working'.

    If you give up fighting the Session, post another entry and you will surely
    be helped...

    bill

    "Tom wilson" <> wrote in message
    news:...
    > Ok, I have the page working using a single static placeholder.
    > That'll do the job. 100% of the content is retrieved from a SQL
    > Server database and everything down to the text is generated
    > dynamcially. I'm just fighting with the session object now. :)
    >
    > I appreciate your help. Thanks!
    >
    >
    > On Wed, 9 Feb 2005 13:50:16 -0600, "William F. Robertson, Jr."
    > <> wrote:
    >
    > >1 - look at the aspx side of the page.
    > >
    > >You will see the form element.
    > >
    > ><form runat="server" id="myForm">
    > >
    > >You can get this control by typing
    > >Form = Page.FindControl( "myForm" );
    > >
    > >Notice the parameter to FindControl is the ID of the control. If ID

    isn't
    > >there, then assign it one.
    > >
    > >ASP.NET is a completely different way of html generation. You really

    can't
    > >think of things such as, "in asp I would just do document.write, etc."

    You
    > >must think of terms of controls.
    > >
    > >I really don't know enough about your requirements to tell you how and

    what
    > >you should be doing, but I wish you the best of luck. There are several
    > >ways to accomplish what you are trying to do.
    > >
    > >Is the entire page dynamic? What determines the content? How much state
    > >information should be maintained.
    > >
    > >bill
    > >
    > >You can always access the Request.Forms("txtName") and get the posted

    values
    > >without worry about setting up control trees.
    > >Also, if you really like the asp rendering module, you can always

    override
    > >the Page.Render method and write out the html using Response.Write.
    > >Although I don't think anyone on this board would recommend that

    approach.
    > >
    > >
    > >
    > >
    > >"Tom wilson" <> wrote in message
    > >news:...
    > >> 1 - How do I find that out? The Class is called "TestForm". It
    > >> appears to inherit from "MyApp.TestForm". Is that what I need?
    > >>
    > >>
    > >> Not complicated? This is a re-write of a survey application
    > >> originally done in asp. For that method, it was as simple as one line
    > >> of HTML to create a textbox and response.write the text/html. With
    > >> this I have to:
    > >>
    > >> 1 - Manually add a placeholder to the empty form. I can't create one
    > >> dynamically, everyt method I've tried fails.
    > >>
    > >> 2 - Create a set of control arrays for each type of control; checkbox,
    > >> radio, etc.
    > >>
    > >> 3 - Redim Preserve each array as the number of controls increases as
    > >> they are created. I hope 500 radios don't eat too much memory.
    > >>
    > >> 4 - Create the control, takes about 5 lines of code not including the
    > >> array tracking.
    > >>
    > >> 5 - Add the newly created control to the placeholder.
    > >>
    > >> ...and everything must be a control. Text? HTML? They have to be
    > >> defined as LiteralControl(s) and added in sequence. I remember when
    > >> it was called "response.write" but if I do that, all the text is at
    > >> the top of the page and the controls underneath because response.write
    > >> doesn't add to a placeholder. I swear if I have to do tables my head
    > >> will explode.
    > >>
    > >> Yes, it's that complicated.
    > >>
    > >> Sorry about the rant, it's been 3 days at this with little progress.
    > >> I do very much appreciate your input.
    > >>
    > >>
    > >>
    > >>
    > >> On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
    > >> <> wrote:
    > >>
    > >> >Couple things.
    > >> >
    > >> >1. What is your page derived from to have a FindForm method?
    > >> >2. Your form is probably called frmTestForm.
    > >> >
    > >> >me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
    > >> >
    > >> >It really isn't that complicated; it is simply a matter of learning

    the
    > >> >framework. Although I do wish MS would have exposed the internal Form
    > >> >property they have. Perhaps this will be modified in 2.0.
    > >> >
    > >> >bill
    > >> >
    > >> >"Tom wilson" <> wrote in message
    > >> >news:...
    > >> >> When I add that line I get "Object reference not set to..." I've
    > >> >> tried it on its own page with nothing else but this:
    > >> >>
    > >> >> Dim Place1 as new Placeholder
    > >> >> me.FindForm("TestForm").Controls.Add(Place1)
    > >> >>
    > >> >> Same result. I have discovered that I can add a placeholder in

    design
    > >> >> view and it will accept control additions. I guess the whole

    problem
    > >> >> is that I cannot create a placeholder dynamically within the form
    > >> >> tags. I don't know why something so simple has to be so

    complicated.
    > >> >>
    > >> >>
    > >> >>
    > >> >> On 8 Feb 2005 23:56:10 -0800, (fd123456) wrote:
    > >> >>
    > >> >> >Hi Tom,
    > >> >> >
    > >> >> >Try this instead of Controls.Add(Place1):
    > >> >> >
    > >> >> >Me.FindControl("Form1").Controls.Add(Place1)
    > >> >> >
    > >> >> >(provided your form is called Form1, obviously, but that's what

    it's
    > >> >> >called by default).
    > >> >> >
    > >> >> >You were adding the radiobuttons in the Page controls, but outside

    of
    > >> >> >the Form controls.
    > >> >> >
    > >> >> >Also note that "Me." is only here for demonstration purposes. You

    can
    > >> >> >omit it, it's implicit.
    > >> >> >
    > >> >> >HTH,
    > >> >> >
    > >> >> >Michel
    > >> >> >
    > >> >> >Tom wilson <> wrote in message
    > >> >news:<>...
    > >> >> >> I'm trying to create dynamic controls in ASP.Net. It's driving

    me
    > >> >> >> nuts. I keep getting the error:
    > >> >> >>
    > >> >> >> Control '16' of type 'RadioButton' must be placed inside a form

    tag
    > >> >> >> with runat=server.
    > >> >> >>
    > >> >> >> Dim Place1 As New PlaceHolder
    > >> >> >> Controls.Add(Place1)
    > >> >> >> For y = 1 To Choices.RecordCount
    > >> >> >> Choices.MoveTo(y)
    > >> >> >> Dim Radio As New RadioButton
    > >> >> >> Radio.ID = choices.ID
    > >> >> >> Radio.Text = choices.ChoiceText
    > >> >> >> Radio.GroupName = Q.ID
    > >> >> >> Place1.Controls.Add(Radio)
    > >> >> >>
    > >> >> >> If I do Controls.Add(Radio) I get the above error. So I created

    a
    > >> >> >> placeholder in design view (there's nothing there since all page
    > >> >> >> content is dynamic). It added the radios but at the bottom of

    the
    > >> >> >> form. So I modified the code to dynamically create the

    placeholder
    > >> >> >> (as above). I STILL get this error.
    > >> >> >>
    > >> >> >> Do I have to do a:
    > >> >> >> response.write("<FORM etc etc... runat=server>")
    > >> >> >> before every checbox creation?
    > >> >> >>
    > >> >> >> Why doesn't it add the tags itself while its creating the

    controls?
    > >> >> >>
    > >> >> >> How do I add a control without getting that needless error at

    every
    > >> >> >> turn?
    > >> >> >>
    > >> >> >> Thanks!
    > >> >>
    > >> >
    > >>

    > >

    >
    William F. Robertson, Jr., Feb 10, 2005
    #8
    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. Matthew Louden
    Replies:
    4
    Views:
    13,026
    Teemu Keiski
    Nov 18, 2003
  2. =?Utf-8?B?QWxpeHggU2tldmluZ3Rvbg==?=

    of type 'TextBox' must be placed inside a form tag with runat=serv

    =?Utf-8?B?QWxpeHggU2tldmluZ3Rvbg==?=, Apr 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    11,480
    =?Utf-8?B?QWxpeHggU2tldmluZ3Rvbg==?=
    Apr 22, 2005
  3. Replies:
    0
    Views:
    2,041
  4. Eliyahu Goldin
    Replies:
    7
    Views:
    250
    Ken Cox [Microsoft MVP]
    Jan 12, 2005
  5. Matthew Louden
    Replies:
    3
    Views:
    171
    Teemu Keiski
    Nov 18, 2003
Loading...

Share This Page