473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Dynamic ASP.NET WebForm

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
Nov 18 '05 #1
2 1710
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
"absolut" <ad****@sudirgo.com> wrote in message
news:9c**************************@posting.google.c om...
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

Nov 18 '05 #2
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
0
by: Mike | last post by:
Hi, I have a class library (dll) in which I defined a class for a custom control (called PlaceHolder). In a separate Web project, I created a custom control (called Template.ascx) that contains...
1
by: Tammy | last post by:
Hi I am working on a portal that will serve up reporting services reports. The user will have a basic home page and from there will be able to run their reports. As each report is run, I need to...
1
by: Peter Wu | last post by:
Hello Group, I create a class that inherits from the System.Web.UI.WebControls.DataGrid class. Basically, what I want to do is to dynamically add a Table that contains some numbers for paging....
7
by: AdeelAlvi | last post by:
iam working on a project called service desk that automates the departmental services online .one major component i have to create is that to convert paper based forms into dynamic webforms . i...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
2
by: muriwai | last post by:
Hi, I am writing a web custom control that displays a dynamically generated image. Apparently I need to register an HTTP handler in web.config. Is there any way to register the handler...
4
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having difficulty understanding how the state is being persisted and how to work with it. I've created a simplified example...
12
by: HyperManTT | last post by:
Hi guys..I was recently asked to create a console application that takes the content of a text file and creates a webform in aspx format based on the the text file. For example if the text file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.