This is the first question I ask on this site, so I apologise for any muckups I make in advance, I will however try to ask this question as best as possible.
I'm finding my problem a little difficult to explain, but it boils down to this:
I have a large string of HTML that is generated by retrieving an XML file from a Web Service and using XSLT to transform it into a large string of HTML. I then parse it into a Control collection, add some event handlers and add it to a HTMLPlaceholder and hooray everything works just fine.
However, since this HTML String contains pretty much my entire website and is being run on hand terminals that cannot handle all the markup at once, I filter the markup I send, but this presents a problem.
Div
elements cannot be filtered out without losing the Div
element I want to keep. This is because Parsecontrol chops my Div
elements in half and turns them into Literalcontrols, which are sorted by br
elements.
Showing my code is a little hard, but here is an example of what happens:
//html contains the auto generated HTML
ctrl = ParseControl (html);
for ( int i = ctrl.Controls.Count - 1 ; i >= 0 ; --i )
{
string MenuId = "";
Control theControl = ctrl.Controls[i];
if ( theControl is Button )
// Code that filters buttons
if ( theControl is TextBox)
// Code that filters textboxes
if ( theControl is LiteralControl )
{
LiteralControl literal = theControl as LiteralControl;
//This checks if the Div element I'm looking for exists
//If it does, I want to keep it
bool contains = literal.Text.Contains ("<div id=\"" + ParentDiv);
if ( contains )
MenuId = ParentDiv;
}
if ( MenuId != ParentDiv )
{
ctrl.Controls.RemoveAt (i);
}
}
It's when I get to the LiteralControl part that things go wrong. Buttons and Textfields work fine. The LiteralControl however, chops my Div elements in half and are filtered by br
elements. My div
elements look like the following(Edited for brevity):
<div class="hide" id="TB_24000" >
<br>
<Textbox elements>
<Button elements>
<Label elements>
<br>
<Textbox elements>
<Button elements>
<Label elements>
<br>
<input type="button" id="btnBack" value="Tilbage" class="BackandResetButtons" onclick="backButton(this,document.getElementById('MenuLevel1'),document.getElementById('TB_24000')); return false;"></div>
But my LiteralControl elements look like the following(unedited):
<br><input type="button" id="btnBack" value="Tilbage" class="BackandResetButtons" onclick="backButton(this, document.getElementById('TB_33999'),document.getElementById('TB_38400'));
 "></div>
And the next:
<br><label class="label">FRAGT</label><br>
And the next:
<br><label class="label">SPEDITØR</label><br>
As you can see, my LiteralControls are based upon br
elements, but the problem is that I want to filter based on Div
elements. However, it doesn't seem to be possible without resorting to dirty and frankly unwanted hacks.
So my question is: How do I filter based on Div
elements instead of Br
elements? I can filter buttons and textboxes that add functionality just fine, but my layout and site is dependent on my Div
elements being there.
Try closing your BR
elements like this: <br />
I think that the parser is getting confused by the BR
element with no closing tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With