dynamic form generation

V

Venus

Hello,

Thanks for your reply.
I understand that a control can be created dynamically in several ways:
1) using StringBuilder
2) using Controls.Add
3) using ASP PlaceHolder

But this is just for the controls and not for the form itself.
What I am trying to achieve is to create an entire form (including controls)
dynamically and place it in HTML when needed.
So my next question would be how to do this ? In other words how to place
the control elements in the dynamic form ?
Assuming of course that the controls have been generated using one of the
above methods.

strForm = "<form name=""someName"" method= .....>"
----------------------------------------------------------
how to place the elements inside the form ???
----------------------------------------------------------
strForm += "</form>"
=========================================================
and now place it in HTML

<td><%=strForm %> </td>
=========================================================

Thanks
 
D

Dale

You can check out the IHttpHandler documentation on MSDN. Implement the
IHttpHandler in a class, override the ProcessRequest method, and register
your handler in the web.config file in the <
httpHandlers> section. It's really pretty easy.

In your ProcessRequest method, you will dynamically produce everything from
the opening <HTML> tag to the ending </HTML> tag.

Hope this helps,

Dale Preston
MCAD, MCSE, MCDBA
 
V

Venus

I created a class, added httpHandler in web.config and placed as
path="test1.aspx"
So what I can do is render whatever HTML I have and display it. And this is
only going to work
for one page or I have to generate a special extension for it and use
path="*.ext" ?!

No, this is not what I need; I have to generate the code in an "aspx"
environment and I should be
able to use it in any number of pages within the webApp.

Does anybody has another suggestions to my question ?

Thanks anyway
 
V

Venus

Hello,

After trying some ways to do it I wanted to use something like the code
below but for some reason
is not working (I have to generate the entire form dynamically (not only the
controls)):
Can anyone make any suggestions on how to do it ?

Thanks

----------------------------------------------------------------------------
---------------------------------------
dim myPlaceHolder as new PlaceHolder
dim btn1 as new Button
dim btn2 as new Button

btn1.Text = "btn 1"
btn2.Text = "btn 2"

myPlaceHolder.Controls.Add(New LiteralControl("<form name='myForm'
runat='server' method='GET'>"))
myPlaceHolder.Controls.Add(btn1)
myPlaceHolder.Controls.Add(btn2)
myPlaceHolder.Controls.Add(New LiteralControl("</form>"))

--------------HTML
SECTION---------------------------------------------------------------------
---------
NOT WORKING

<td><asp:placeholder id=myPlaceHolder runat=server></asp:placeholder></td>
----------------------------------------------------------------------------
---------------------------------------
WORKS (but is not what I need)
----------------------------------------------------------------------------
-------------------------------------
<td>
<form runat=server>
<asp:placeholder id=myPlaceHolder runat=server></asp:placeholder>
</form>
</td>
----------------------------------------------------------------------------
---------------------------------------







============================================================================
======
 
D

DujHoD

All you are doing is generating literal text that will be rendered to
the browser as

<form name='myForm' runat='server' method='GET'>

So it will be parsed by the user agent, but not by the page compiler,
which knows that it is just a LiteralControl. You cannot dynamically
create the server form itself (AFAIK). But why would you want to? Why
not just put the server form statically on the page and add controls
to it as necessary?
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top