Bruno, if I understand correctly, the solution is fairly simple.
Let's say your page is default.aspx?FormId=XXX where formId is the dynamic
form created by the admin, in the .aspx page you'd put a placeholder
<asp:placeholder id="formHolder" runat="Server" />
in codebehind you'd do something like (not actual code)
protected formHolder as System.Web.UI.PlaceHolder
Sub Page_Load
dim formId as integer = cint(Request.QueryString("formId")) 'error checks
need to be added
dim dt as datable = GetForm(formId)
for each row as DataRow in dt.rows
dim c as Control
select case cstr(row("Type")).ToUpper()
case "TEXTBOX":
c = new TextBox()
case "BUTTON"
c = new Button()
end select
c.style.add("position", "relative")
c.style.add("top", cstr(row("Top")))
c.style.add("top", cstr(row("Left")))
c.id = cstr(row("name"))
formHolder.controls.add(c)
next
End Sub
private function GetForm(formId as integer) as datatable
'Hit the database and popupate a Datatable for all the fields for the
given form
'I would expect the DT to have these columns: Type string, name string,
left int, top int
return datatable
end function
In other words, get each item, dynamically create them and add them to the
placeHolder. Now you can get more creative if you need to support, say a
label for each field, or if you have a dropdownlist or a radiobuttonlist and
you need to support multiple values (with perhaps a default selected
one)....all of that can be achieved by simply enriching your datatable or
adding datarelations (even better) and handing it in a similar way.
Karl
"Bruno Pimentel Machado" <Br******************@discussions.microsoft.com>
wrote in message news:5D**********************************@microsof t.com...
is it possible (how) to build a asp.net page on the fly?
i.e.: I have a db with the controls I want to add to it:
1. TextBox - name "ABC" - Text "CDE" - Left 10 - Top - 30
2. Button - name "BT1" - Text "TXT" - Left 30 - Top 100
I have the following issue...
I am trying to build a simple CRM tool... - I've done this before in VB
(Client-Server) - and I thought it would be great in asp.net (c#)...
so far - no problem...
one of the featurings of the system is to build the scripts (some admin
builds the layout of some scripting page - labels, checkboxes, textboxes).
The regular user has to fill it and the information has to be stored in a
db.
if I build my own the scripts (aspx pages) - no problem...
but I do have to let this "admin" built it at runtime...
so he/she has to login, set the controls he/she wants to display, set
their position and the associated field to the db...
the only way I found (and I haven't tried it yet) is to take the compiler
within the server and compile every time the admin creates/changes
something
--
Bruno Pimentel Machado
Software Engineer
Brazil - Sao Paulo