Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Asp.net add html controls to aspx form at run time , use them like server controls



Hi ,

I have to  add html to my aspx form at run time and use added  controls as server cotrols ..
let says
 I need to create one form in which html comes from db . and then control in that behave like server control .
 
  first table that contains html for form  .

 <table><tr><td>First name</td><td><input type="text" name="fist_name" size="40" ></td></tr>
        <tr><td>Last name</td><td><input type="text" name="last_name" size="20" ></td></tr>
</table > 

and  second table that contains two field fist_name and last_name .  
when i run that from it show two text box (above html of first table  ) and
on button click value of textboxex to be save in second table  .
please help .
thanks  in advance
0
eteran
Asked:
eteran
  • 3
1 Solution
 
abelCommented:
That's quite a story. I'm not planning to do your work for you, I hope you settle with a few pointers Sounds to me that you would be better of using GridView or Repeater or related controls for your data from your database. But if you want to create them by hand, you can do that like this (see the comments for the explanations, paste the code in the page_load):





' create html table '
Dim htmlTable As New HtmlTable()
Dim htmlTableRow As New HtmlTableRow()
 
' first name cell and ' 
Dim htmlTableCell As New HtmlTableCell
htmlTableCell.InnerHtml = "First name"
 
' add cell to row ' 
htmlTableRow.Cells.Add(htmlTableCell)
 
' input field ctrl '
Dim htmlInput As New HtmlInputText
htmlInput.Name = "first_name"
htmlInput.Size = 40
 
' input field cell and adding the ctrl to the cell '
htmlTableCell = New HtmlTableCell
htmlTableCell.Controls.Add(htmlInput)
 
' add cell to row '
htmlTableRow.Cells.Add(htmlTableCell)
 
' add rows to the table '
htmlTable.Rows.Add(htmlTableRow)
 
' add table to the page ' 
Me.Controls.Add(htmlTable)

Open in new window

0
 
abelCommented:
To work with dynamic controls and to create them is a lot of work. All you said in your post can also be done by just typing that structure in the  ASPX page and giving the relevant elements an runat="server" to make them server controls. The button should be an asp:Button and the textboxes should be asp:TextBox to make it easier to reference them.
0
 
eteranAuthor Commented:
hi abel  thanks for reply
   i have  add lots of html and we can't break it  .
  So we can't use your first way we are already using that .
  we have to add html as it is ...
thanks
0
 
abelCommented:
@TheLearnedOne: it might be that you misinterpreted the last comment of "eteran", here's my reading of the same:

>> "so we can't use your first way". My "first way" was the suggestion to use a gridview.
>> "we have to add html as it is". That was what I showed as an example. The asker here confirms that he's going for my approach, which is shown in the comment of http:#24190323

And then forgot to grade... ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now