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.C ontrols.Add(New LiteralControl( "<form name='myForm'
runat='server' method='GET'>") )
myPlaceHolder.C ontrols.Add(btn 1)
myPlaceHolder.C ontrols.Add(btn 2)
myPlaceHolder.C ontrols.Add(New LiteralControl( "</form>"))
--------------HTML SECTION------------------------------------------
NOT WORKING
<td><asp:placeh older id=myPlaceHolde r runat=server></asp:placeholder ></td>
----------------------------------------------------------------------------
WORKS (but is not what I need)
----------------------------------------------------------------------------
<td>
<form runat=server>
<asp:placeholde r id=myPlaceHolde r runat=server></asp:placeholder >
</form>
</td>
----------------------------------------------------------------------------
=============== =============== =============== =============== ========
"Venus" <so**@gal.net > wrote in message
news:bTCNc.1228 69$eO.114936@ed tnps89...
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><%=strFor m %> </td>
=============== =============== =============== ============
Thanks
"SMG" <SM*@nodmain.co m> wrote in message
news:OS******** ******@TK2MSFTN GP09.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>He llo!!! Can you see me");
strBuild.Append ("</asp:Label>");
Page.Controls.A dd( Page.ParseContr ol(strBuild.ToS tring()));
// 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.A dd(lblName);
Regards,
Shailesh MG
"Venus" <so**@gal.net > wrote in message
news:WbmNc.1031 75$Rf.2421@edtn ps84...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:butto n name=""myName"" .... runat=""server" " />" & vbCrLf strForm += "<asp:butto n ....... runat=""server" " />" & vbCrLf
strForm += "</form>" & vbCrLf
--
The problem this code is placed as a string "ad literam" without
generatingthe elements.use
If I would use normal input fields this works fine but would like toASPcontrols 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 %>
.....