Hi Al,
I see more-or-less what you're trying to do. Unfortunately, I don't
think that you can duplicate the Access behavior in a Web Project, mainly
because there is no out-of-the-box "container" ( like .. Access ) that
contains a list of forms.
The only similar entity I can think of for a web project would be the
actual virtual directory or web site in IIS. you can get programmatic access
to IIS through WMI using .NET ( I think ), but you can also do that using
scripting, check out the IIS Admin scripts under webroot on your IIS
installation. However, at best I think you'd only be able to get a list of
"files" or "forms" under the site root & sub-folders, without having the
distinction between data entry forms & other sorts of pages there ...
If I could recommend another approach ? If you've already invested time in
ASP.NET web Forms code it will seem a lot of hussle, but ... it's the only
thing I can think of off the top of my head:
You could generate the data entry forms dynamically. For instance, we have
defined data entry forms in xml here, and use that to generate an HTML
interface through XSL. Then, as the form is posted, all forms go to the same
..aspx ( or HttpHandler ), which uses the form xml to instantiate the
required validators with the needed parameters, validate the form data, and
do whatever if validation is successful, or return the user to the form
indicating the errors.
Our form description looks something like this:
<?xml version="1.0" encoding="utf-8" ?>
<forms>
<form id="Register" xsl-file="form.xsl" handler-class="">
<fields>
<field id="uname" type="TextField">
<validators>
<validator
class="System.Web.UI.WebControls.RequiredFieldValidator">
<properties>
<property name="InitialValue" value=""/>
<property name="ErrorMessage" value="Please fill-in the
required field: Password"/>
</properties>
</validator>
</validators>
</field>
</fields>
</form>
</forms>
... i know, it's kinda bloated, but let's leave that aside for a minute -
we're working on that
If you use this xml-based approach, you could work on the forms, fields &
validators, because you have all the forms defined in the xml, which is
something you can work with in a much simpler way. It wouldn't be hard to
create some sort of UI for Form creation & editing.
It all boils down in the impementation of the engine, the two aspx pages
that will be used for displaying the form, and processing the input.
Something like this:
http://localhost/dynforms/DisplayForm.aspx?form=Register
&
http://localhost/dynforms/ProcessForm.aspx?form=Register&uname=whatever (
assuming that you're using GET, but using POST doesn't really change
anything in the implementation. I do it so that I can see that it actually
passes the parameters correctly,and I'll switch to POST afterwards ... )
The displaying part is easy. All you need to do is create some simple XSL to
generate an HTML form from the xml, and just write that out directly to your
Response output stream.
the processing part is a bit trickier - mainly because ASP.NET validators
are actually UI components as far as ASP.NET is concerned, so you'll have to
write some trivial code to add them onto the page, despite the fact that
nothing will be displayed ... :? .. it's one of those things with ASP.NET I
guess ...
...but in the end of all this, you'll have an excellent(?) way of producing
data entry forms, at the same time being able to edit them, add/remove
fields, validators and end-point behavior (save to DB ? e-mail the form
contents ? both ? whatever else ? ) completely dynamically.
It's worked wonders for me so far, being able to add validating forms to a
site with a single xml description ( I should point out though that you only
get server-side validation this way, otherwise you'll really have to do some
XSL wonders to generate & add the client-side validation Javascript .. )
If you do decide to follow this approach however, bear in mind that you'd
better create aome class hierarchy & parse the xml inot objects if you've
got too many forms on your project. Keeping an xml file of 200K in memory is
a bit of an overhead for your server. The same xml in object form is much
smaller in memory size.
Well, that's what I think :] hope this helped a bit cos' it took me 10' to
write
Angel
O:]
ALthePal said:
Hi Tim,
Sort of ... we have a product that is in an Access database and we have
upsized most of the forms and code to VB.NET (ADO.NET, Oracle/SQL server). We
have a feature in the Access version that allows users to validate data on
various forms in the system through a wizard. In order for users to be able
to easily create their own data validation on data input forms, we have a
wizard that allows them to view the "chosen" form, view the data fields and
create the validation for the fields. We need all our form information in a
table to allow this feature (in our product).
What I am trying to do is to programmatically extract the form information
and save them to the table without having to add additional lines of code to
every form.
I hope this information helps.
Thanks,
Alice