Click here to Skip to main content
15,891,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I want to add a control at specific tag.
for example:
I have the following html/asp tags
HTML
<h2>
        page 1</h2>
    <div id="DynFormDiv">

    </div>


Now, I want to add a control (for example textbox) at this div (DynFormDiv).
How can I achieve this?
Posted

C#
HtmlTable ht=new HtmlTable();
HtmlTableRow r1 =new HtmlTableRow();
HtmlTableCell c1=new HtmlTableCell();
c1.InnerHtml="Name";
r1.Cells.Add(c1);
TextBox t1=new TextBox();
HtmlTableCell c2=new HtmlTableCell();
c2.Controls.Add(t1);
r1.Cells.Add(c2);
ht.Rows.Add(r1);
..................... so on... can do it inside loop also
Form1.Controls.Add(ht);
 
Share this answer
 
Comments
Rasool Ahmed 15-Sep-13 4:34am    
Thanx
then you can add generic control to page and add control to that generic like this
C#
HtmlGenericControl div=new HtmlGenericControl("div");
div.ID="div3";
for(int i=0;i<5;i++)
{
 TextBox t=new TextBox();
 div.Controls.Add(t);
}
this.Form1.Controls.Add(div);
 
Share this answer
 
Comments
Rasool Ahmed 14-Sep-13 13:12pm    
Consider this:
I have a table, and have loop. In each loop generate cell into table.
I want to add some controls in specific cells inside the table.
How to achieve this?
Zafar A khan 15-Sep-13 0:18am    
this is easy just Use HtmlTable and add controls dynamically at specific index/cell
Rasool Ahmed 15-Sep-13 3:10am    
How can I do this?
use asp:panel bcz panel also renders to div element
the add textboxes to it like the following
C#
<asp:panel id="pnltest" runat="server"></asp:panel>

for (int i=0; i<5; i++)
{
  TextBox t=new TextBox();
  pnltest.Controls.Add(t);
}
 
Share this answer
 
v2
Comments
Rasool Ahmed 14-Sep-13 6:56am    
How can I add panel into div (DynFormDiv) at runtime?
I just don't want to add any control at design time.
Hi..
First make the div runat=server.


Private Sub CreateControl()
Dim txt1 As New Textbox
txt1.width="350px"
MyDiv.Controls.Add(txt1)
End Sub

Page_Init() Handles Page.Init
CreateControl()
End Sub

Call the createcontrols sub in page-init so the controls can be registered in the page and also survive during postbacks..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900