Dynamic ASP.NET WebForm

A

absolut

I'm trying to build a dynamic web form using ASP.NET.
Basically I've defined all the fields for the form in the database.
When the aspx is launched, it will first grab those values from the
SQL DB as an XML, then I'm using XSLT to display the form.
Here's the background VB code:

Public Sub displayForm()
Dim sqlconn As New Data.SqlClient.SqlConnection
Dim sqlcmd As New Data.SqlClient.SqlCommand
Dim myXR As System.Xml.XmlTextReader
Dim xmldoc As New XmlDocument
Dim strXMLHeaderTag As String

Try
sqlconn.ConnectionString = Application("SQLConnStr")
sqlconn.Open()

sqlcmd.Connection = sqlconn
sqlcmd.CommandText = "SELECT * FROM tblFormField Field
ORDER BY Field.FieldOrder FOR XML AUTO, ELEMENTS"

myXR = sqlcmd.ExecuteXmlReader()
myXR.MoveToContent()

'Because XMLDOC will only accept well-formatted XML
string: XML wrapped within 1 top-root-tag
strXMLHeaderTag = "<Top>"
While Not myXR.EOF
strXMLHeaderTag &= myXR.ReadOuterXml
End While
strXMLHeaderTag &= "</Top>"

xmldoc.LoadXml(strXMLHeaderTag)
Dim xslTran As XslTransform = New XslTransform
xslTran.Load(Server.MapPath("test.xslt"))

Dim sw As StringWriter
sw = New StringWriter
xslTran.Transform(xmldoc, Nothing, sw)

Response.Write(sw.ToString)

Catch exp As Exception
Response.Write("Error in opening DB! index.displayform() "
& exp.ToString)
End Try
End Sub

And this is the XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0">
<xsl:for-each select="Top/Field">
<tr>
<xsl:variable name="fieldname" select="FieldName" />
<xsl:variable name="fieldorder" select="FieldOrder" />
<td><xsl:value-of select="NameDisplay"/>: </td>
<td><INPUT id="txt{$fieldorder}" style="WIDTH: 190px; HEIGHT:
22px" size="29" name="{$fieldname}"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Everything is okay until this point. It can display the form
correctly.
However, I'm confused as how to grabs the user-input values from the
textbox?
Because when user click the "Submit" button, back to the VB code, in
the Submit_Click() function, I'm supposed to get the value of each
textbox. But then, I can't simply just do "textboxname.Text", because
the name of the textbox itself is only defined during run-time (in the
XSLT)!

And how can I make an iteration to make sure that I get all the
textboxes (Note that the number of textboxes in the form varies
depending on how many fields I've defined in the DB).

Can anybody help? Thanks a lot!

Adrian
 
F

Freddy

After clicking the submit loop through the controls in the Page. Check if
the control is a text box and then retrieve the values.

Freddy
 
A

Adrian Sudirgo

Thanks for the reply Freddy, but sorry, I don't really understand how to
check the control. I mean how to loop through the control?

Thanks,

Adrian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top