G
Guest
Hello All:
I am trying to dynamically populate a web page with literal content and
controls (textboxes and checkboxes (and eventually two buttons - the buttons
do not appear in the code yet). I read an xml file and, using the values
retrieved from it, determine what text should be displayed and which controls
should be rendered and - most importantly - where those controls should be
rendered.
The ultimate goal is to have some text followed by a control that will
capture the users response and post it back to the server. For example the
page might show:
Please enter the dollar amount: [textbox goes here].
Was this an accident? [checkbox for yes] Yes [checkbox for no] No
The problem is that all of the controls are rendered at the top of the page
and all of the text renders after the closing html tag. I don't know why
this is and I don't know enough about the Render method to speak
intelligently about it. I hope that I have explained clearly what I am
trying to do. If not please let me know.
The code is here:
Structure DynamicControl
Dim Type As String
Dim FieldType As String
Dim Name As String
Dim FieldName As String
Dim Size As String
Dim MaxLength As String
Dim EntryType As String
End Structure
Private doc As XmlDocument
Private Lines As XmlNodeList
Private ReqData As XmlNodeList
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.BufferOutput = True
Dim Line As XmlNode
Dim ChildNode As XmlNode
Dim DynamicEntry As XmlNode
output = New HtmlTextWriter(txtWtr)
doc = New XmlDocument
doc.Load("C:\SampleForm.xml")
Lines = doc.GetElementsByTagName("Line")
ReqData = doc.GetElementsByTagName("Data")
For Each Line In Lines
If Line.HasChildNodes Then
For Each ChildNode In Line.ChildNodes
Dim attrList As XmlAttributeCollection =
ChildNode.Attributes
If Not (attrList Is Nothing) Then
Dim DynCtl As DynamicControl =
ParseDynamicCtrlData(attrList.GetNamedItem("id").Value)
Select Case DynCtl.FieldType.ToLower
Case "checkbox"
Dim c As CheckBox = New CheckBox
c.ID = attrList.GetNamedItem("id").Value
c.Text = DynCtl.Name
Me.Controls(1).Controls.Add(c)
Case "text"
Dim t As TextBox = New TextBox
t.ID = attrList.GetNamedItem("id").Value
t.MaxLength = CType(DynCtl.MaxLength, Integer)
t.Text = DynCtl.Name
Me.Controls(1).Controls.Add(t)
End Select
Else
Dim lit As Literal = New Literal
lit.Text = Line.InnerText & "<br/>"
Me.Controls.Add(lit)
End If
Next
Else
Dim lit As Literal = New Literal
lit.Text = Line.InnerText & "<br/>"
Me.Controls.Add(lit)
End If
Next
End Sub
Private Function ParseDynamicCtrlData(ByVal id As String) As
DynamicControl
Dim DataNode As XmlNode
Dim dc As DynamicControl
For Each DataNode In ReqData
If String.Compare(DataNode.Attributes("name").Value, id) = 0 Then
dc.FieldType = DataNode.Attributes("fieldtype").Value
If dc.FieldType.ToLower = "text" Then
If String.Compare(DataNode.Attributes("type").Value,
"merge") <> 0 Then
dc.FieldName = DataNode.Attributes("fieldname").Value
dc.Name = DataNode.Attributes("name").Value
dc.Size = DataNode.Attributes("size").Value
dc.MaxLength = DataNode.Attributes("maxlength").Value
End If
ElseIf dc.FieldType.ToLower = "checkbox" Then
dc.FieldName = DataNode.Attributes("fieldname").Value
dc.Name = DataNode.Attributes("name").Value
End If
Exit For
End If
Next
Return dc
End Function
The XML is here:
<Form>
<Content>
<Line><Dynamic type="text" id="DateField"/></Line>
<Line/>
<Line><Dynamic type="text" id="CustomAddress1"/></Line>
<Line><Dynamic type="text" id="CustomAddress2"/></Line>
<Line><Dynamic type="text" id="CustomAddress3"/></Line>
<Line><Dynamic type="text" id="CustomAddress4"/></Line>
<Line/>
<Line/>
<Line>RE: Your File #: <Dynamic type="text" id="YourFile"/></Line>
<Line> Your Insured: <Dynamic type="text" id="YourInsured"/></Line>
<Line> Our File #: <Dynamic type="text" id="OurFile"/></Line>
<Line> Our Insured: <Dynamic type="text" id="OurInsured"/></Line>
<Line> Date of Loss: <Dynamic type="text" id="DateOfLoss"/></Line>
<Line/>
<Line>We are asking you to please complete the following with regard to
your No-Fault file on the above mentioned insured.</Line>
<Line/>
<Line>Medical paid: <Dynamic type="text" id="MedicalPaid"/></Line>
<Line>Wage Loss paid: <Dynamic type="text" id="WageLossPaid"/></Line>
<Line>Essential Services paid: <Dynamic type="text"
id="EssentialServicesPaid"/></Line>
<Line>Advise if threshold passed: <Dynamic
type="checkbox" id="AdviseThresholdYes"/> Yes <Dynamic type="checkbox"
id="AdviseThresholdNo"/> No</Line>
<Line>Have you conducted an IME at this time? <Dynamic
type="checkbox" id="ConductedIMEYes"/> Yes <Dynamic
type="checkbox" id="ConductedIMENo"/> No</Line>
<Line>If not, do you contemplate scheduling one? <Dynamic
type="checkbox" id="ContemplateSchedulingYes"/> Yes <Dynamic
type="checkbox" id="ContemplateSchedulingNo"/> No</Line>
<Line>Nature of injury <Dynamic type="text" id="NatureOfInjury"/></Line>
<Line>We thank you for your cooperation and are enclosing a return envelope
for your convenience.</Line>
<Line/>
<Line>Sincerely,</Line>
<Line/>
<Line/>
<Line/>
<Line/>
<Line><Dynamic type="text" id="AdjusterName"/></Line>
<Line><Dynamic type="text" id="AdjusterPhone"/></Line>
<Line/>
<Line>Claims Department</Line>
<Line/>
<Line/>
<Line>WB-204 (12-99)</Line>
</Content>
<RequiredData>
<Data fieldtype="NowDate" name="DateField"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress1"
fieldname="CustomAddress1" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress2"
fieldname="CustomAddress2" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress3"
fieldname="CustomAddress3" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress4"
fieldname="CustomAddress4" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="YourFile" fieldname="YourFile"
size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="YourInsured"
fieldname="YourInsured" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="OurFile" fieldname="OurFile"
size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="OurInsured"
fieldname="OurInsured" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="DateOfLoss"
fieldname="DateOfLoss" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="MedicalPaid"
fieldname="MedicalPaid" size="30" maxlength="20" entrytype="Numeric"/>
<Data type="Entry" fieldtype="Text" name="WageLossPaid"
fieldname="WageLossPaid" size="30" maxlength="20" entrytype="Numeric"/>
<Data type="Entry" fieldtype="Text" name="EssentialServicesPaid"
fieldname="EssentialServicesPaid" size="30" maxlength="20"
entrytype="Numeric"/>
<Data type="Entry" fieldtype="Checkbox" name="AdviseThresholdYes"
fieldname="AdviseThresholdYes"/>
<Data type="Entry" fieldtype="Checkbox" name="AdviseThresholdNo"
fieldname="AdviseThresholdNo"/>
<Data type="Entry" fieldtype="Checkbox" name="ConductedIMEYes"
fieldname="ConductedIMEYes"/>
<Data type="Entry" fieldtype="Checkbox" name="ConductedIMENo"
fieldname="ConductedIMENo"/>
<Data type="Entry" fieldtype="Checkbox" name="ContemplateSchedulingYes"
fieldname="ContemplateSchedulingYes"/>
<Data type="Entry" fieldtype="Checkbox" name="ContemplateSchedulingNo"
fieldname="ContemplateSchedulingNo"/>
<Data type="Entry" fieldtype="Text" name="NatureOfInjury"
fieldname="NatureOfInjury" size="30" maxlength="30"/>
<Data type="Merge" fieldtype="Text" name="AdjusterName"
fieldname="AdjusterName" size="30" maxlength="30"/>
<Data type="Merge" fieldtype="Text" name="AdjusterPhone"
fieldname="AdjusterPhone" size="30" maxlength="30"/>
</RequiredData>
</Form>
Any help would be greatly appreciated.
I am trying to dynamically populate a web page with literal content and
controls (textboxes and checkboxes (and eventually two buttons - the buttons
do not appear in the code yet). I read an xml file and, using the values
retrieved from it, determine what text should be displayed and which controls
should be rendered and - most importantly - where those controls should be
rendered.
The ultimate goal is to have some text followed by a control that will
capture the users response and post it back to the server. For example the
page might show:
Please enter the dollar amount: [textbox goes here].
Was this an accident? [checkbox for yes] Yes [checkbox for no] No
The problem is that all of the controls are rendered at the top of the page
and all of the text renders after the closing html tag. I don't know why
this is and I don't know enough about the Render method to speak
intelligently about it. I hope that I have explained clearly what I am
trying to do. If not please let me know.
The code is here:
Structure DynamicControl
Dim Type As String
Dim FieldType As String
Dim Name As String
Dim FieldName As String
Dim Size As String
Dim MaxLength As String
Dim EntryType As String
End Structure
Private doc As XmlDocument
Private Lines As XmlNodeList
Private ReqData As XmlNodeList
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.BufferOutput = True
Dim Line As XmlNode
Dim ChildNode As XmlNode
Dim DynamicEntry As XmlNode
output = New HtmlTextWriter(txtWtr)
doc = New XmlDocument
doc.Load("C:\SampleForm.xml")
Lines = doc.GetElementsByTagName("Line")
ReqData = doc.GetElementsByTagName("Data")
For Each Line In Lines
If Line.HasChildNodes Then
For Each ChildNode In Line.ChildNodes
Dim attrList As XmlAttributeCollection =
ChildNode.Attributes
If Not (attrList Is Nothing) Then
Dim DynCtl As DynamicControl =
ParseDynamicCtrlData(attrList.GetNamedItem("id").Value)
Select Case DynCtl.FieldType.ToLower
Case "checkbox"
Dim c As CheckBox = New CheckBox
c.ID = attrList.GetNamedItem("id").Value
c.Text = DynCtl.Name
Me.Controls(1).Controls.Add(c)
Case "text"
Dim t As TextBox = New TextBox
t.ID = attrList.GetNamedItem("id").Value
t.MaxLength = CType(DynCtl.MaxLength, Integer)
t.Text = DynCtl.Name
Me.Controls(1).Controls.Add(t)
End Select
Else
Dim lit As Literal = New Literal
lit.Text = Line.InnerText & "<br/>"
Me.Controls.Add(lit)
End If
Next
Else
Dim lit As Literal = New Literal
lit.Text = Line.InnerText & "<br/>"
Me.Controls.Add(lit)
End If
Next
End Sub
Private Function ParseDynamicCtrlData(ByVal id As String) As
DynamicControl
Dim DataNode As XmlNode
Dim dc As DynamicControl
For Each DataNode In ReqData
If String.Compare(DataNode.Attributes("name").Value, id) = 0 Then
dc.FieldType = DataNode.Attributes("fieldtype").Value
If dc.FieldType.ToLower = "text" Then
If String.Compare(DataNode.Attributes("type").Value,
"merge") <> 0 Then
dc.FieldName = DataNode.Attributes("fieldname").Value
dc.Name = DataNode.Attributes("name").Value
dc.Size = DataNode.Attributes("size").Value
dc.MaxLength = DataNode.Attributes("maxlength").Value
End If
ElseIf dc.FieldType.ToLower = "checkbox" Then
dc.FieldName = DataNode.Attributes("fieldname").Value
dc.Name = DataNode.Attributes("name").Value
End If
Exit For
End If
Next
Return dc
End Function
The XML is here:
<Form>
<Content>
<Line><Dynamic type="text" id="DateField"/></Line>
<Line/>
<Line><Dynamic type="text" id="CustomAddress1"/></Line>
<Line><Dynamic type="text" id="CustomAddress2"/></Line>
<Line><Dynamic type="text" id="CustomAddress3"/></Line>
<Line><Dynamic type="text" id="CustomAddress4"/></Line>
<Line/>
<Line/>
<Line>RE: Your File #: <Dynamic type="text" id="YourFile"/></Line>
<Line> Your Insured: <Dynamic type="text" id="YourInsured"/></Line>
<Line> Our File #: <Dynamic type="text" id="OurFile"/></Line>
<Line> Our Insured: <Dynamic type="text" id="OurInsured"/></Line>
<Line> Date of Loss: <Dynamic type="text" id="DateOfLoss"/></Line>
<Line/>
<Line>We are asking you to please complete the following with regard to
your No-Fault file on the above mentioned insured.</Line>
<Line/>
<Line>Medical paid: <Dynamic type="text" id="MedicalPaid"/></Line>
<Line>Wage Loss paid: <Dynamic type="text" id="WageLossPaid"/></Line>
<Line>Essential Services paid: <Dynamic type="text"
id="EssentialServicesPaid"/></Line>
<Line>Advise if threshold passed: <Dynamic
type="checkbox" id="AdviseThresholdYes"/> Yes <Dynamic type="checkbox"
id="AdviseThresholdNo"/> No</Line>
<Line>Have you conducted an IME at this time? <Dynamic
type="checkbox" id="ConductedIMEYes"/> Yes <Dynamic
type="checkbox" id="ConductedIMENo"/> No</Line>
<Line>If not, do you contemplate scheduling one? <Dynamic
type="checkbox" id="ContemplateSchedulingYes"/> Yes <Dynamic
type="checkbox" id="ContemplateSchedulingNo"/> No</Line>
<Line>Nature of injury <Dynamic type="text" id="NatureOfInjury"/></Line>
<Line>We thank you for your cooperation and are enclosing a return envelope
for your convenience.</Line>
<Line/>
<Line>Sincerely,</Line>
<Line/>
<Line/>
<Line/>
<Line/>
<Line><Dynamic type="text" id="AdjusterName"/></Line>
<Line><Dynamic type="text" id="AdjusterPhone"/></Line>
<Line/>
<Line>Claims Department</Line>
<Line/>
<Line/>
<Line>WB-204 (12-99)</Line>
</Content>
<RequiredData>
<Data fieldtype="NowDate" name="DateField"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress1"
fieldname="CustomAddress1" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress2"
fieldname="CustomAddress2" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress3"
fieldname="CustomAddress3" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="CustomAddress4"
fieldname="CustomAddress4" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="YourFile" fieldname="YourFile"
size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="YourInsured"
fieldname="YourInsured" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="OurFile" fieldname="OurFile"
size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="OurInsured"
fieldname="OurInsured" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="DateOfLoss"
fieldname="DateOfLoss" size="30" maxlength="30"/>
<Data type="Entry" fieldtype="Text" name="MedicalPaid"
fieldname="MedicalPaid" size="30" maxlength="20" entrytype="Numeric"/>
<Data type="Entry" fieldtype="Text" name="WageLossPaid"
fieldname="WageLossPaid" size="30" maxlength="20" entrytype="Numeric"/>
<Data type="Entry" fieldtype="Text" name="EssentialServicesPaid"
fieldname="EssentialServicesPaid" size="30" maxlength="20"
entrytype="Numeric"/>
<Data type="Entry" fieldtype="Checkbox" name="AdviseThresholdYes"
fieldname="AdviseThresholdYes"/>
<Data type="Entry" fieldtype="Checkbox" name="AdviseThresholdNo"
fieldname="AdviseThresholdNo"/>
<Data type="Entry" fieldtype="Checkbox" name="ConductedIMEYes"
fieldname="ConductedIMEYes"/>
<Data type="Entry" fieldtype="Checkbox" name="ConductedIMENo"
fieldname="ConductedIMENo"/>
<Data type="Entry" fieldtype="Checkbox" name="ContemplateSchedulingYes"
fieldname="ContemplateSchedulingYes"/>
<Data type="Entry" fieldtype="Checkbox" name="ContemplateSchedulingNo"
fieldname="ContemplateSchedulingNo"/>
<Data type="Entry" fieldtype="Text" name="NatureOfInjury"
fieldname="NatureOfInjury" size="30" maxlength="30"/>
<Data type="Merge" fieldtype="Text" name="AdjusterName"
fieldname="AdjusterName" size="30" maxlength="30"/>
<Data type="Merge" fieldtype="Text" name="AdjusterPhone"
fieldname="AdjusterPhone" size="30" maxlength="30"/>
</RequiredData>
</Form>
Any help would be greatly appreciated.