Solved add html controls to aspx  form at run time  , use them like server controls

Posted on 2009-04-20
Last Modified: 2012-05-06

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
Question by:eteran
    LVL 39

    Accepted Solution

    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 ' 
    ' 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
    ' add cell to row '
    ' add rows to the table '
    ' add table to the page ' 

    Open in new window

    LVL 39

    Expert Comment

    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.

    Author Comment

    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 ...
    LVL 39

    Expert Comment

    @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... ;-)

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

    Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now