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