I tried looking for similar questions but couldn't find any. My aspx file looks something like this
<div align="center" style="height: 350px; overflow-y: scroll; overflow-x: scroll; width: 100%;">
<asp:Table ID="tblReport" Font-Size="11px" runat="server" ViewStateMode="Enabled">
<asp:TableHeaderRow Height="30px" ForeColor="#FFFFFF" BackColor="#3b3b3b" Style="font-weight: bold; text-align: left !important; padding-left: 3px; color: #FFF; border-right: 1px solid #ddeaf7;" HorizontalAlign="Center">
</asp:TableHeaderRow>
</asp:Table>
</div>
Now whenever there are too many columns, the width gets fixed to 100% even though I don't have a max-width property. And the text in the cell ends up in multiple lines. I want it to horizontally overflow out of the div instead.
Edit: Looks like adding this ended up fixing it.
td {
white-space: nowrap;
}
Simple html snippet to demonstrate -
div {
width: 10%;
overflow: auto;
}
<div>
<table>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
<th>G</th>
<th>H</th>
<th>I</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
</div>
EDIT -
Your updated code would look like -
<div align="center" style="height: 350px; overflow: auto; width: 100%;">
<asp:Table ID="tblReport" Font-Size="11px" runat="server" ViewStateMode="Enabled">
<asp:TableHeaderRow Height="30px" ForeColor="#FFFFFF" BackColor="#3b3b3b" Style="font-weight: bold; text-align: left !important; padding-left: 3px; color: #FFF; border-right: 1px solid #ddeaf7;" HorizontalAlign="Center">
</asp:TableHeaderRow>
</asp:Table>
</div>
Related
I have a string (HTML) being posted to server side and then it is validated using HTMLAgility pack. In the HTML there is an unclosed colgroup tag.
After sanitizing, the closing colgroup tag appears but right between closing "tbody" and "table" tag
BEFORE:
<table width="3265" class="mce-item-table" style="width: 2452pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<colgroup><col width="80" style="width: 60pt;">
<col width="245" style="width: 184pt;" span="13"> <!-- MISSING COLGROUP tag-->
<tbody><tr height="20" style="height: 15pt;">
<td width="80" height="20" style="width: 60pt; height: 15pt; color: blue; text-decoration: underline; text-underline-style: single;"><span style="color: blue;">31109173</span></td>
<td width="245" style="width: 184pt; font-family: Arial; font-size: 9pt;">31109173</td>
<td width="245" align="right" style="width: 184pt; font-family: Arial; font-size: 9pt;">May 09,2017 9:54 AM</td>
<td width="245" align="right" style="width: 184pt; font-family: Arial; font-size: 9pt;">May 08,2017 5:21 PM</td>
</tr>
<tr height="20" style="height: 15pt;">
<td height="20" style="height: 15pt; color: blue; text-decoration: underline; text-underline-style: single;"><span style="color: blue;">30933775</span></td>
<td style="font-family: Arial; font-size: 9pt;">30933775</td>
<td align="right" style="font-family: Arial; font-size: 9pt;">May 09,2017 9:50 AM</td>
<td align="right" style="font-family: Arial; font-size: 9pt;">Apr 28,2017 6:22 PM</td>
</tr>
</tbody></table>
AFTER:
<table width="3265" class="mce-item-table" style="width: 2452pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<colgroup><col width="80" style="width: 60pt;">
<col width="245" style="width: 184pt;" span="13">
<tbody><tr height="20" style="height: 15pt;">
<td width="80" height="20" style="width: 60pt; height: 15pt; color: blue; text-decoration: underline; text-underline-style: single;"><span style="color: blue;">31109173</span></td>
<td width="245" style="width: 184pt; font-family: Arial; font-size: 9pt;">31109173</td>
<td width="245" align="right" style="width: 184pt; font-family: Arial; font-size: 9pt;">May 09,2017 9:54 AM</td>
<td width="245" align="right" style="width: 184pt; font-family: Arial; font-size: 9pt;">May 08,2017 5:21 PM</td>
</tr>
<tr height="20" style="height: 15pt;">
<td height="20" style="height: 15pt; color: blue; text-decoration: underline; text-underline-style: single;"><span style="color: blue;">30933775</span></td>
<td style="font-family: Arial; font-size: 9pt;">30933775</td>
<td align="right" style="font-family: Arial; font-size: 9pt;">May 09,2017 9:50 AM</td>
<td align="right" style="font-family: Arial; font-size: 9pt;">Apr 28,2017 6:22 PM</td>
</tr>
</tbody></colgroup></table>
<!-- ^^ </colgroup> has appeared above-->
I tried setting "OptionFixNestedTags" flag to true. I still get the same result.
I tried various options from HTMLAgility pack and setting them true. This didn't work.
OptionFixNestedTags = true;
OptionAutoCloseOnEnd = true;
There is a nice Nuget package which sanitizes the html. The problem which I faced was tackled here -> HtmlSanitizer
Hope this helps.
today i have certain problem using user control (.ascx) in asp.net technology. currently, i have scenario where the ideas are to put modal jquery mobile modal into ascx. then save the data based on click. for this condition, i have this coding
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="IndexPanel1.ascx.cs" Inherits="WebPGN.Pages.control.indexPanel1" %>
<style>
.btn-size {
width: 50px !important;
}
</style>
<div>
<i class="icon-pencil"></i>
<div data-role="popup" id="myPopup" style="width: 1000px;" data-history="false">
<div class="modal-header">
<h4 style="font-family: '__Helvetica Neue LT Std_5'; font-weight: 500; font-size: 16px;"><i class="icon-edit"></i> Edit Information</h4>
Close
</div>
<div class="modal-body">
<div class="col-md-12">
<table class="table table-responsive" border="0" style="border-color: #FFFFFF;">
<tr class="form-group">
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Header Text</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<asp:TextBox runat="server" ID="txt_Panel1_Header_Eng" Visible="true" EnableViewState="true" ClientIDMode="Static" />
</td>
<td style="width: 3%; border-top: 0px solid #f4f4f4 !important;"></td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Judul Teks</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<asp:TextBox runat="server" ID="txt_Panel1_Header" ClientIDMode="Static" />
</td>
</tr>
<tr class="form-group">
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Body Text</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<textarea rows="6" cols="90" id="txt_Panel1_Body_Eng" runat="server" style="height: 250px;"></textarea>
</td>
<td style="width: 3%; border-top: 0px solid #f4f4f4 !important;"></td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Konten Teks</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<textarea rows="6" cols="90" id="txt_Panel1_Body" runat="server" style="height: 250px;"></textarea>
</td>
</tr>
<tr class="form-group">
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Tag</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<asp:TextBox runat="server" ID="txt_Panel1_Tag_Eng" ClientIDMode="Static"/>
</td>
<td style="width: 3%; border-top: 0px solid #f4f4f4 !important;"></td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 10%;">Label</td>
<td style="vertical-align: middle; border-top: 0px solid #f4f4f4 !important; font-family: '__Helvetica Neue LT Std_5'; font-weight: 300; width: 30%;">
<asp:TextBox runat="server" ID="txt_Panel1_Tag" ClientIDMode="Static"/>
</td>
</tr>
</table>
</div>
</div>
<div class="modal-footer" style="border-top: 0px solid #e5e5e5;" id="modal-footer">
<a class="btn btn-primary" href="#myPopup" data-rel="back" style="color: #fff;">Cancel</a>
<a class="btn btn-primary" href="#myPopup" ID="btnSaveHomePanel1" data-rel="back" runat="server" style="color: #fff;">Save</a>
</div>
</div>
</div>
for some reason, i want to use this ascx for example to send data to the server side. however, i have problem because when using asp.net button, the event doesnot fire back. can anyone give me more advice to accomplish this current condition. or should i use bootstrap modal rather than jquery mobile ui ? and how to use ascx as modal ? thank you very much :)
PS: i am using
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
you have to try bootstrap Modal like
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-2.2.4.js"
integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
crossorigin="anonymous"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<asp:LinkButton ID="btn_SearchCriteria" runat="server" Text="Search Vehicles" data-toggle="modal" data-target="#myModal"><p class="btn btn-primary">Purchasing Tool</p></asp:LinkButton>
<div aria-labelledby="myModalLabel" class="modal fade" id="myModal" role="dialog" tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h1 style="font-size: 18px; font-weight: 600">Purchasing Tool and Analysis</h1>
<button type="button" class="close pull-right" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<asp:Panel ID="pnlSubItems" runat="server" CssClass="modalBox" Width="100%">
<asp:Repeater runat="server" ID="repVehicleInfo" OnItemDataBound="repVehicleInfo_ItemDataBound">
<ItemTemplate>
<ul class="media-list">
<li class="media">
<div class="media-left">
<img src="../../images/SystemImages/car-avatar.png" style="width: 250px; height: 200px" />
<br />
<asp:Label ID="lbl_stockno" runat="server" Style="font-weight: 600" Text='<%# Bind("StockNumber") %>'></asp:Label>
</div>
<div class="media-body">
<%--2001 Holden Astra TS 12/00-12/04--%>
<h1 class="media-heading" style="font-weight: 600">
<asp:Label ID="lbl_heading" runat="server" Text='<%# Bind("Description") %>'></asp:Label></h1>
<div class="col-sm-8">
<table class="table table-responsive">
<tr>
<td>Body Style:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_bodystyle" runat="server" Text='<%# Bind("BodyType") %>'></asp:Label>
</td>
</tr>
<tr>
<td>Engine:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_engine" runat="server" Text='<%# Bind("Engine") %>'></asp:Label>
</td>
</tr>
<tr>
<%-- <td>License No:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_linceno" runat="server"></asp:Label>
</td>--%>
<td>Transmission:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_transmission" runat="server" Text='<%# Bind("Engine") %>'></asp:Label>
</td>
</tr>
<tr>
<%-- <td>Reg No:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_regno" runat="server"></asp:Label>
</td>--%>
<td>Odometer:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_odometer" runat="server" Text='<%# Bind("Odometer") %>'></asp:Label>
</td>
</tr>
<tr>
<%-- <td>Color:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_color" runat="server"></asp:Label>
</td>--%>
<td>Purchased From:</td>
<td style="font-weight: 600">
<asp:Label ID="lbl_PurchasedFrom" runat="server" Text='<%# Bind("PurchasedFrom") %>'></asp:Label>
</td>
</tr>
<tr>
<td>Purchase Amount:</td>
<td style="font-weight: 600">$<asp:Label ID="lbl_PurchaseAmount" runat="server" Text='<%# Bind("PurchaseAmount") %>'></asp:Label>
</td>
</tr>
<tr>
<td>Sale Amount:</td>
<td style="font-weight: 600">$<asp:Label ID="lbl_SaleAmount" runat="server" Text='<%# Bind("SalesAmount") %>'></asp:Label>
<button id="lbtn_makemodel" href="#makemodel" type="button" class="btn btn-sm btn-primary pull-right" data-toggle="modal">
<i class="fa fa-cogs" aria-hidden="true"></i>Make/Model</button>
</td>
</tr>
<tr>
<td>Estimated Profit:</td>
<td style="font-weight: 600">
$<asp:Label ID="lbl_Estimatedprofit" runat="server" Text='<%# Bind("EstimatedProfit") %>'></asp:Label>
<button id="lbtn_anaylse" href="#anaylse" type="button" class="btn btn-sm btn-primary pull-right" data-toggle="modal"><i class="fa fa-pie-chart" aria-hidden="true"></i>Anaylse</button>
</td>
</tr>
<tr>
<td>App Price:</td>
<td style="font-weight: 600">
$<asp:Label ID="lbl_AppPrice" runat="server" Text='<%# Bind("PurchaseAmount") %>'></asp:Label>
</td>
</tr>
</table>
</div>
<div class="col-sm-4">
<asp:Repeater runat="server" ID="repPartsDetail">
<HeaderTemplate>
<ul class="list-group">
</HeaderTemplate>
<ItemTemplate>
<li class="list-group-item">
<asp:Label ID="lbl_Partname" runat="server" Text="Engine" />
<span class="badge">
$<asp:Label ID="lbl_partprice" runat="server" Text="0" Style="float: right;" />
</span>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
First of all add Bootstrap CSS and Bootstrap JS.
then Use this code
This code work for me. like when i click on linked button Bootstrap Modal Show
you can use this Webcontrol Any where and bind data on CodeBhind in ascx.cs file
A HTML file is generated by Android MobileBiz Pro invoice app. I'm trying to make software for print HTML based invoice via receipt printer
I need to save necessary information of HTML file to string variable as mentioned below. I tried using IndexOf method. but it's not working for me. How can I get this information using visual c#?
string subtotal = 2,976.00;
string total = 2,976.00;
string payment= 2,760.00;
string balance= 216.00;
This is an example of the HTML code:
<tr><td align="right" colspan="3">Subtotal</td><td align="right">2,976.00</td></tr><tr><td align="right" colspan="3"><b>TOTAL</b></td><td align="right"><b>2,976.00</b></td></tr><tr><td align="right" colspan="3">Less Payment</td><td align="right">2,760.00</td></tr><tr class="total"><td align="right" colspan="3"><strong>Balance Due</strong></td><td align="right">216.00</td></tr>
This is a complete HTML code of HTML file
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
body {
font-family:Verdana, Geneva, sans-serif;
font-size: 8pt;
padding: 0 50pt 0 50pt;
}
table td, table th, table.sales th, table td.footer-text {
font-size: 8pt;
}
h1 {
font-family:Verdana, Geneva, sans-serif;
padding-bottom:2px;
margin-bottom:2px;
color:chocolate;
text-transform:uppercase;
font-size: inherit;
font-size: 1.5em;
}
h2 {
font-family:Verdana, Geneva, sans-serif;
padding-bottom:0px;
margin-bottom:0px;
color:chocolate;
text-transform:uppercase;
font-size: 1.3em;
}
h3 {
font-family:Verdana, Geneva, sans-serif;
padding-bottom:2px;
margin-bottom:2px;
}
table.sales td {
padding: 4px 10px 4px 10px;
}
table.sales th {
padding: 5px 10px 5px 10px;
background-color:#CCC;
}
tr.saleline td {
border-bottom-color:chocolate;
border-bottom-width: 1pt;
border-bottom-style: solid;
vertical-align: top;
}
.signature {
display: none;
}
.horizontal-line {
border: 0;
height: 4pt;
color:chocolate;
background-color: chocolate;
}
.total {
font-weight:bold;
font-size:1.1em;
background-color:#CCC;
}
.block1 {
text-align:left;
vertical-align:bottom
}
.block2 {
text-align:right;
vertical-align:bottom
}
.block3 {
text-align:left;
vertical-align:top;
}
.block4 {
text-align:left;
vertical-align:top;
}
.block5 {
text-align:right;
vertical-align:bottom;
}
.block6 {
text-align:left;
vertical-align:top;
margin-top: 15px;
}
.block7 {
text-align:left;
vertical-align:top;
margin-top: 15px;
}
.block8 {
text-align:left;
vertical-align:bottom;
}
.block9 {
text-align:center;
vertical-align:bottom;
}
.block10 {
text-align:right;
vertical-align:bottom;
}
.block11 {
text-align:left;
padding: 25px 0 15px 0;
}
.extracols {
border-style:solid;
border-color:gray;
}
table.extracols {
border-top-width: 1pt;
border-right-width: 0;
border-bottom-width: 1pt;
border-left-width: 1pt;
border-collapse:collapse;
margin: 0 0 15pt 0;
}
table.extracols th {
padding: 5px 10px 5px 10px;
border-top-width: 0;
border-right-width: 1pt;
border-bottom-width: 0;
border-left-width: 0;
border-color:gray;
border-style:solid;
background-color:#CCC;
}
table.extracols td {
padding: 4px 10px 4px 10px;
border-top-width: 0;
border-right-width: 1pt;
border-bottom-width: 0;
border-left-width: 0;
border-color:gray;
border-style:solid;
background-color:#FFF;
}
#footer {
margin-top: 35px;
}
.footer-text {
font-size: inherit;
font-size: 0.97em
}
</style>
</head>
<body style="padding: 20 20 20 20">
<table width="100%">
<tr>
<td style="padding-bottom:20px"><table width="100%">
<tr>
<td style="text-align:left;"></td>
<td class="block2" align="right"><h3>Y.P.Brothers</h3>
No:55/B,<br/>Samagipura,<br/>Sewanagala.
<br/>077-6977139
<br/>mecduino#gmail.com
<br/>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><hr class="horizontal-line"/></td>
</tr>
<tr>
<td><table width="100%">
<tr>
<td style="padding:10px 0 20px 0;"><table width="100%">
<tr>
<td width="33%" class="block3"><strong>Bill To</strong><br />
ANUSHA SURIYA<br/>
</td>
<td class="block4"><strong></strong><br />
</td>
<td class="block5" align="right"><h1>invoice #1</h1>
<b>Date</b>: Oct 9, 2015
<br/><b>Due Date</b>: Oct 9, 2015
</td>
</tr>
</table></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td><table width="100%" class="sales">
<!-- Headers -->
<tr>
<th align="center">Qty</th> <th align="center">Item</th> <th align="right">Price</th> <th align="right">Amount</th>
</tr>
<!-- Rows -->
<tr class="saleline"> <td align="left">12</td> <td align="left">helaligth 35/=</td> <td align="right">35.00</td> <td align="right">420.00</td> </tr>
<tr class="saleline"> <td align="left">12</td> <td align="left">200p CR SR 195/=</td> <td align="right">195.00</td> <td align="right">2,340.00</td> </tr>
<tr class="saleline"> <td align="left">36</td> <td align="left">Sunlight 35g</td> <td align="right">6.00</td> <td align="right">216.00</td> </tr>
<!-- Totals -->
<tr><td align="right" colspan="3">Subtotal</td><td align="right">2,976.00</td></tr><tr><td align="right" colspan="3"><b>TOTAL</b></td><td align="right"><b>2,976.00</b></td></tr><tr><td align="right" colspan="3">Less Payment</td><td align="right">2,760.00</td></tr><tr class="total"><td align="right" colspan="3"><strong>Balance Due</strong></td><td align="right">216.00</td></tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" style="margin-top:30px">
<tr>
<td width="50%" class="block6"><h2></h2>
</td>
<td width="50%" class="block7" align="right"><h2></h2>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><table class="block11" width="100%">
<tr>
<td><table></table></td>
</tr>
</table></td>
</tr>
<tr>
<td></td>
</tr>
</table>
<div class="signature">
<table border="0" cellspacing="2" cellpadding="2" align="left">
<tr>
<td style="padding-bottom:30px"></td>
</tr>
<tr>
<td><b>Signed by:</b>
<br/><b>Date:</b>
<br/><b>Signature:</b><br/></td>
</tr>
</table>
</div>
<div id="footer">
<table width="100%" border="0" cellpadding="2">
<tr>
<td align="center"><span class="footer-text">Thank you for your business.</span></td>
</tr>
</table>
</div>
</body>
</html>
You need an html parser, try this one http://htmlagilitypack.codeplex.com/
Load page into HtmlDocument
HtmlWeb htmlWeb = new HtmlWeb();
HtmlDocument htmlDocument = htmlWeb.Load("url");
Get table with specified Id
HtmlNode table = htmlDocument.DocumentNode.Descendants("table").SingleOrDefault(x => x.Id == "tableId");
Loop through nodes to find values
foreach(HtmlNode child in table.ChildNodes)
{
if (child.NodeType != HtmlNodeType.Text)
{
Console.WriteLine(child.Name);
}
}
More you can check here http://www.codeproject.com/Articles/691119/Html-Agility-Pack-Massive-information-extraction-f
You have to use parseHTML function of jquery and then loop through each element to get the values. Below is the working example (It can be more refined as per your need)
$(document).ready(function () {
var str = '<tr><td align="right" colspan="3">Subtotal</td><td align="right">2,976.00</td></tr><tr><td align="right" colspan="3"><b>TOTAL</b></td><td align="right"><b>2,976.00</b></td></tr><tr><td align="right" colspan="3">Less Payment</td><td align="right">2,760.00</td></tr><tr class="total"><td align="right" colspan="3"><strong>Balance Due</strong></td><td align="right">216.00</td></tr>';
var html = $.parseHTML(str);
$.each(html, function (index, element) {
if ($(this).find("td:first").html() == "Subtotal")
console.log($(this).find("td:last").html());
else if ($(this).find("td:first b").html() == "TOTAL")
console.log($(this).find("td:last b").html());
else if ($(this).find("td:first").html() == "Less Payment")
console.log($(this).find("td:last").html());
else if ($(this).find("td:first strong").html() == "Balance Due")
console.log($(this).find("td:last").html());
});
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an HTML saved in a.txt file which looks like this.
<HTML> <HEAD> <TITLE></TITLE> </HEAD>
<BODY STYLE="font: 10pt Times New Roman, Times, Serif"> <P STYLE="margin: 0"></P> <P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center">UNITED STATES</P> <P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center">SECURITIES AND EXCHANGE COMMISSION</P> <P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center">WASHINGTON, D.C. 20549</P>
<P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center"> </P> <P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center"></P> <P STYLE="font: 10pt Times New Roman, Times, Serif; margin: 0pt 0; text-align: center"><B> </B></P>
<TABLE CELLSPACING="0" CELLPADDING="0" STYLE="font: 10pt Times New Roman, Times, Serif; width: 100%; border-collapse: collapse"> <TR STYLE="vertical-align: top"> <TD STYLE="width: 5%; padding-right: 5.4pt; padding-left: 5.4pt"><FONT STYLE="font-size: 10pt">[X]</FONT></TD> <TD STYLE="width: 95%; padding-right: 5.4pt; padding-left: 5.4pt"><FONT STYLE="font-size: 10pt">ANNUAL REPORT UNDER SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934</FONT></TD></TR> <TR STYLE="vertical-align: top">
<TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"></TD>
<TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"> </TD></TR> <TR STYLE="vertical-align: top"> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"></TD>
<TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt; text-align: right"><FONT STYLE="font-size: 10pt">For the fiscal year ended <B><U>October 31, 2012</U></B></FONT></TD></TR> <TR STYLE="vertical-align: top"> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"></TD> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"> </TD></TR> <TR STYLE="vertical-align: top"> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"><FONT STYLE="font-size: 10pt">[ ]</FONT></TD> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"><FONT STYLE="font-size: 10pt">TRANSITION REPORT UNDER SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934</FONT></TD></TR> <TR STYLE="vertical-align: top">
<TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"></TD> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"> </TD></TR> <TR STYLE="vertical-align: top">
<TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt"></TD> <TD STYLE="padding-right: 5.4pt; padding-left: 5.4pt; text-align: right"><FONT STYLE="font-size: 10pt">For the transition period from _________ to ________</FONT></TD></TR>
I need text which preserves Newline. All these text are getting combined into a single line. How to handle this? Below is my C# code
string text = File.ReadAllText(#"C:\a.txt",Encoding.UTF8);
Regex regex = new Regex("<[^>]+>");
text = regex.Replace(text, " ").Replace("( )+", Environment.NewLine).Replace(" ", "").Replace("’", "'").Replace("\r\n\r\n(\r\n)+", Environment.NewLine);
text = HttpUtility.HtmlDecode(text);
Console.WriteLine(text);
I would never use regex to parse HTML, instead, use the HtmlAgilityPack, you can do a lot of things just using simple XQuery/XPath, example:
HtmlDocument doc = new HtmlDocument();
doc.Load(#"C:\temp\stackoverflow\question23657841\question23657841\a.html");
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//p"))
{
Console.WriteLine(node.InnerHtml);
}
The output is:
UNITED STATES
SECURITIES AND EXCHANGE COMMISSION
WASHINGTON, D.C. 20549
<b> </b>
And simply switching the XQuery to //font you get this:
[X]
ANNUAL REPORT UNDER SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934
For the fiscal year ended <b><u>October 31, 2012</u></b>
[ ]
TRANSITION REPORT UNDER SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934
For the transition period from _________ to ________
Why not read File line by line File.ReadAllLines() does just that
aspx code
<asp:ModalPopupExtender ID="MPE" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="pnlGame" CancelControlID="imgCloseBtn" TargetControlID="btnHidden">
</asp:ModalPopupExtender>
<asp:Button runat="server" ID="btnHidden" Style="display: none" />
<asp:Panel ID="pnlGame" runat="Server" CssClass="pnl">
<div class="MsgPopup">
<%--<fieldset class="">--%>
<table style="height: 100%; width: 100%;">
<tr>
<td colspan="2" style="padding-top: 5px; padding-left: 4px;">
<table border="0" class="" style="width: 500px;">
<tr>
<td align="center">
<img src="../img/exclaimationIcon.jpg" width="65px" height="56px" alt="" />
</td>
</tr>
<tr>
<td align="center">
<div id="GameName" style="font-size: medium; width: 500px; font-size: 17px; font-weight: bold;
font-family: Arial; color: Black; font-variant: normal">
Please select the Child, From and To Dates
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align="center">
<asp:ImageButton ID="imgCloseBtn" runat="server" Height="38px" ImageUrl="~/img/okButton.jpg"
Width="91px" ToolTip="Close" CausesValidation="False" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</asp:Panel>
cs code:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "TestInitPageScript031",
string.Format("<script type=\"text/javascript\">ShowReport();</script>"), false);
Javascript Code:
<script type="text/javascript">
function ShowReport() {
var Asgn1 = document.getElementById("<%=ddlAssignments.ClientID%>").value;
var Assn1 = document.getElementById("<%=ddlAssessment.ClientID%>").value;
var Asgn2 = document.getElementById("<%=ddlAssignments1.ClientID%>").value;
var Assn2 = document.getElementById("<%=ddlAssessment1.ClientID%>").value;
alert(Asgn1);
if (Asgn1 == 0)
{
$find('<%= MPE.ClientID %>').show();
return false;
}
}
</script>
Here is my brief code.Problem is my modal pop up is not displaying. I can trace by alret in alert i am getting 0; but modal pop up not displaying. Can anyone help me to resolve?
asp:ModalPopupExtender is a Server control.
If you want to show it you ave to post a server side Show() event; client side (javascript I mean) won't work.
If you need to work client side, using jQuery, you don't need a server side control: an hidden div set at the top of the window will be enough for you.
HTML
<div class="outerframe">
<div class="innerframe" >
...
CSS
.outerframe {
background: url('../Images/site-bg2.png');
width: 100%;
height: 100%;
position:absolute;
display:block;
text-align: center;
top: 0px;
left: 0px;
z-index: 1000;
}
.innerframe {
position: relative;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 1200px;
text-align: left;
overflow: auto;
background: #ffffff; /* Fills the page */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#eeeeee)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ffffff, #eeeeee); /* for firefox 3.6+ */
}
Set BehaviorID for modal popup extender..
<asp:ModalPopupExtender ID="MPE" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="pnlGame" CancelControlID="imgCloseBtn" BehaviorID="PopUp"TargetControlID="btnHidden">
</asp:ModalPopupExtender>
Javascript:
<script type="text/javascript">
function ShowReport() {
var Asgn1 = document.getElementById("<%=ddlAssignments.ClientID%>").value;
var Assn1 = document.getElementById("<%=ddlAssessment.ClientID%>").value;
var Asgn2 = document.getElementById("<%=ddlAssignments1.ClientID%>").value;
var Assn2 = document.getElementById("<%=ddlAssessment1.ClientID%>").value;
alert(Asgn1);
if (Asgn1 == 0)
{
$find("<%=ModalPopupExtender1.BehaviorID%>").show();
return false;
}
}
</script>
Refer this for extra reading..