472,108 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,108 software developers and data experts.

dynamic form generation

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
"SMG" <SM*@nodmain.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Dear Vinus,

Here is the Code:::: ( You can copy paste the below given code in
page_Load )
StringBuilder strBuild= new StringBuilder();
strBuild.Append("<asp:Label id=one ");
strBuild.Append(" runat=server>Hello!!! Can you see me");
strBuild.Append("</asp:Label>");
Page.Controls.Add( Page.ParseControl(strBuild.ToString()));

// Second Way of Coding... Create Your Control on the Fly

Label lblName = new Label();
lblName.ID = "NewID";
lblName.Text = "My New Label to display ";
Page.Controls.Add(lblName);

Regards,
Shailesh MG
"Venus" <so**@gal.net> wrote in message
news:WbmNc.103175$Rf.2421@edtnps84...
Hello,

I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows

Build up the string that is placed somewhere in the HTML code the same way like regular input fields can.

strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf
strForm += "<asp:button name=""myName"" .... runat=""server"" />" & vbCrLf strForm += "<asp:button ....... runat=""server"" />" & vbCrLf
strForm += "</form>" & vbCrLf

--

The problem this code is placed as a string "ad literam" without

generating
the elements.
If I would use normal input fields this works fine but would like to use

ASP
controls if possible.
Is there a way to do what I am trying to do here ?

I don't want to do the code generation in the HTML section by mixing HTML with VB code
<% If something %>
<asp:button name= ... />
<% Else %>
.....


Nov 18 '05 #1
4 3176
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

"Venus" <so**@gal.net> wrote in message
news:bTCNc.122869$eO.114936@edtnps89...
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
"SMG" <SM*@nodmain.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Dear Vinus,

Here is the Code:::: ( You can copy paste the below given code in
page_Load )
StringBuilder strBuild= new StringBuilder();
strBuild.Append("<asp:Label id=one ");
strBuild.Append(" runat=server>Hello!!! Can you see me");
strBuild.Append("</asp:Label>");
Page.Controls.Add( Page.ParseControl(strBuild.ToString()));

// Second Way of Coding... Create Your Control on the Fly

Label lblName = new Label();
lblName.ID = "NewID";
lblName.Text = "My New Label to display ";
Page.Controls.Add(lblName);

Regards,
Shailesh MG
"Venus" <so**@gal.net> wrote in message
news:WbmNc.103175$Rf.2421@edtnps84...
Hello,

I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows

Build up the string that is placed somewhere in the HTML code the same way like regular input fields can.

strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf
strForm += "<asp:button name=""myName"" .... runat=""server"" />" & vbCrLf strForm += "<asp:button ....... runat=""server"" />" & vbCrLf
strForm += "</form>" & vbCrLf

--

The problem this code is placed as a string "ad literam" without

generating
the elements.
If I would use normal input fields this works fine but would like to
use
ASP
controls if possible.
Is there a way to do what I am trying to do here ?

I don't want to do the code generation in the HTML section by mixing

HTML with VB code
<% If something %>
<asp:button name= ... />
<% Else %>
.....



Nov 18 '05 #2
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

"Dale" <da************@msndotcomNot.Net> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

"Venus" <so**@gal.net> wrote in message
news:bTCNc.122869$eO.114936@edtnps89...
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
"SMG" <SM*@nodmain.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Dear Vinus,

Here is the Code:::: ( You can copy paste the below given code in
page_Load )
StringBuilder strBuild= new StringBuilder();
strBuild.Append("<asp:Label id=one ");
strBuild.Append(" runat=server>Hello!!! Can you see me");
strBuild.Append("</asp:Label>");
Page.Controls.Add( Page.ParseControl(strBuild.ToString()));

// Second Way of Coding... Create Your Control on the Fly

Label lblName = new Label();
lblName.ID = "NewID";
lblName.Text = "My New Label to display ";
Page.Controls.Add(lblName);

Regards,
Shailesh MG
"Venus" <so**@gal.net> wrote in message
news:WbmNc.103175$Rf.2421@edtnps84...
> Hello,
>
> I am trying to generate a dynamic form at runtime and would like to
do it
> using "<asp: ..." form elements as follows
>
> Build up the string that is placed somewhere in the HTML code the
same way
> like regular input fields can.
>
> strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf
> strForm += "<asp:button name=""myName"" .... runat=""server"" />" &

vbCrLf
> strForm += "<asp:button ....... runat=""server"" />" & vbCrLf
> strForm += "</form>" & vbCrLf
>
> --
>
> The problem this code is placed as a string "ad literam" without
generating
> the elements.
> If I would use normal input fields this works fine but would like to

use ASP
> controls if possible.
> Is there a way to do what I am trying to do here ?
>
> I don't want to do the code generation in the HTML section by mixing

HTML
> with VB code
> <% If something %>
> <asp:button name= ... />
> <% Else %>
> .....
>
>



Nov 18 '05 #3
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>
----------------------------------------------------------------------------
---------------------------------------



================================================== ==========================
======
"Venus" <so**@gal.net> wrote in message
news:bTCNc.122869$eO.114936@edtnps89...
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
"SMG" <SM*@nodmain.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Dear Vinus,

Here is the Code:::: ( You can copy paste the below given code in
page_Load )
StringBuilder strBuild= new StringBuilder();
strBuild.Append("<asp:Label id=one ");
strBuild.Append(" runat=server>Hello!!! Can you see me");
strBuild.Append("</asp:Label>");
Page.Controls.Add( Page.ParseControl(strBuild.ToString()));

// Second Way of Coding... Create Your Control on the Fly

Label lblName = new Label();
lblName.ID = "NewID";
lblName.Text = "My New Label to display ";
Page.Controls.Add(lblName);

Regards,
Shailesh MG
"Venus" <so**@gal.net> wrote in message
news:WbmNc.103175$Rf.2421@edtnps84...
Hello,

I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows

Build up the string that is placed somewhere in the HTML code the same way like regular input fields can.

strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf
strForm += "<asp:button name=""myName"" .... runat=""server"" />" & vbCrLf strForm += "<asp:button ....... runat=""server"" />" & vbCrLf
strForm += "</form>" & vbCrLf

--

The problem this code is placed as a string "ad literam" without

generating
the elements.
If I would use normal input fields this works fine but would like to
use
ASP
controls if possible.
Is there a way to do what I am trying to do here ?

I don't want to do the code generation in the HTML section by mixing

HTML with VB code
<% If something %>
<asp:button name= ... />
<% Else %>
.....



Nov 18 '05 #4
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?
"Venus" <so**@gal.net> wrote in message news:<kLJNc.125492$eO.532@edtnps89>...
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>
----------------------------------------------------------------------------
---------------------------------------

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Tim Pascoe | last post: by
6 posts views Thread by alexandre damiron | last post: by
11 posts views Thread by Marco Loskamp | last post: by
reply views Thread by Venus | last post: by
reply views Thread by Venus | last post: by
3 posts views Thread by RahimAsif | last post: by
2 posts views Thread by Ghada Al-Mashaqbeh via DotNetMonster.com | last post: by
5 posts views Thread by pittendrigh | last post: by
reply views Thread by Eniac | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.