asp.net c# show the html rendering - asp.net

I am trying to retreive pull up the following:
<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;">
<tr>
<td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td>
<td valign="top" class="j">
<font style="font-size:85%;font-family:arial,sans-serif"><br />
<div style="padding-top:0.8em;">
<img alt="" height="1" width="1" />
</div>
<div class="lh">
<a href="http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNEjddVUpIXf528-P5S0D0z5A0_QjQ&url=http://www.daytondailynews.com/news/news/local/letter-points-to-plumbing-in-2011-legionnaires-out/nSmCp/">
<b>Letter points to plumbing in 2011 <b>Legionnaires</b>' outbreak at hospital</b></a><br /><font size="-1">
<b><font color="#6f6f6f">Dayton Daily News</font></b></font><br />
<font size="-1">A letter entered into court records identifies for the first time several factors that may have caused an outbreak of <b>Legionnaire's disease</b> in Miami Valley Hospital's new 12-story patient tower shortly after it opened in late 2010. The outbreak, at the <b>...</b></font><br /><font size="-1" class="p"></font><br />
<font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dRROval94f0jKyM&ned=us"><nobr><b></b></nobr></a></font></div></font>
</td>
</tr>
</table>
Which is formatted in html on my .aspx page.
I am doing the following:
<%# XPath("description").ToString()%>
but it is not showing me the html rendering of it. What I like to show it to me converted into HTML.
as description is already in HTML, why is it not showing it to me?

Use Literal Control
<asp:Literal id="Literal1" runat="server" text='<%# XPath("description").ToString() %>' />

Related

How to add blank row in grid view?

I am new to the ASP.NET i am binding one list of data object to the grid view. I want to display blank row after each record in grid view so i have done this by as below in code behind
List<DatabaseDTO> lstdatabase= new List<DatabaseDTO>();
foreach(int jobNumber in JobnumberList)
{
DatabaseDTO dataObject = new DatabaseDTO();
dataobject = GetDatabaseData(jobNumber);//Method to retrieve data and return data object
lstdatabase.Add(dataObject);
lstdatabase.Add(new DatabaseDTO());
}
gridView.DataSource = lstdatabase;
gridView.DataBind();
it's working correct i am getting the desired blank row in the grid view but i know this is not right way because i am adding object to the list so i can add the blank row in place of that i would very much like to adjust this blank row from the aspx page. I know there is another way using the DataTable but it is also not very good because it also adds the unnecessary records to the DataTable. So any other work around or way to solve this would be very great. Thank you.
Try This
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderTemplate>
<table width="900px">
<tr>
<td width="300px">
<b>Name</b>
</td>
<td width="300px">
<b>Account No</b>
</td>
<td width="300px">
<b>Company</b>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table width="900px">
<tr>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "AccountNo")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Company")%>
</td>
</tr>
<tr>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<SeparatorTemplate><br /></SeparatorTemplate>
</asp:DataList>
</div>
You can't have an empty row in the Datagrid if it isn't present in the data source. You have to think that after all the grid data is just a representation of your data source, if there is a empty row, the grid will show it, if there is not, it wont.
Write a stored procedure to get Output Parameter from sql server and bind to grid view if record is not there..

asp.net RadRotator using xPath

I am using a RadRotator as following for getting an RSS feed from google:
<telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
ScrollDuration="2000" runat="server" DataSourceID="XmlDataSource1" Width="493"
ItemWidth="493" Height="192" ItemHeight="75" FrameDuration="1" InitialItemIndex="-1"
CssClass="rotator">
<%# XPath("item") %>
</ItemTemplate>
What is happening is that nothing is showing in the radgrid when I do
<%# XPath("item") %>
Note that I need item as this is has the title, desciption etc. a you can see in the sniplet below
but if I do
<%# XPath("description") %>
I see the description but the item is what I need..
Here is what a sniplet of the google rss xml file looks like:
<rss version="2.0"><channel><generator>NFE/1.0</generator><title>malaria - Google News</title><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link><language>en</language><webMaster>news-feedback#google.com</webMaster><copyright>©2012 Google</copyright><pubDate>Thu, 25 Oct 2012 14:56:08 GMT</pubDate><lastBuildDate>Thu, 25 Oct 2012 14:56:08 GMT</lastBuildDate><image><title>malaria - Google News</title><url>https://ssl.gstatic.com/news/img/logo/en_us/news.gif</url><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link></image><item><title>Malaria and Acquired Immunity - AllAfrica.com</title><link>http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNHNkVuoonL7HkcwkSoAldZPsWUvNg&url=http://allafrica.com/stories/201210251151.html</link><guid isPermaLink="false">tag:news.google.com,2005:cluster=http://allafrica.com/stories/201210251151.html</guid><pubDate>Thu, 25 Oct 2012 12:16:20 GMT</pubDate><description><table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><b><b>Malaria</b> and Acquired Immunity</b><br /><font size="-1"><b><font color="#6f6f6f">AllAfrica.com</font></b></font><br /><font size="-1">Even though the economic impact in Zambia has not yet been quantified, it is likely to be substantial due to the number of productive days lost due to the number of productive days lost due to <b>malaria</b>. The intensity of <b>malaria</b> in an area determines the <b>...</b></font><br /><font size="-1" class="p"></font><br /><font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dPdXW_JAl88mIRM&ned=us"><nobr><b>and more »</b></nobr></a></font></div></font></td></tr></table></description></item>
Note that I am just trying to get the item portion of it as the item is the wrapper for description,etc.
here is the code snippet for your scenario:
XML Data Source Definition:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&q=malaria&output=rss"
XPath="rss/channel/item"></asp:XmlDataSource>
RadRotator definition:
<telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
ScrollDuration="1000" runat="server" DataSourceID="XmlDataSource1" Width="493"
ItemWidth="493" Height="250" ItemHeight="250" FrameDuration="2000" InitialItemIndex="-1"
CssClass="rotator">
<ItemTemplate>
<div style="border: 1px solid darkgray; padding : 10px;background-color:lightgrey">
<a href='<%# XPath("link") %>'><%# XPath("title") %></a>
<div>
<%# XPath("description") %>
</div>
</div>
</ItemTemplate>
</telerik:RadRotator>
The way to reach an item in RSS feed is through the path rss/channel/item - this will give all the items in the document. Then in the item template i am just grabbing the link, title and description. Item is a parent node and thats why
Here is the output of the above code:

Print and Print Preview missing data in IE8

In a specific screen I need to let the user print out some data. Due to the complexity of the data displayed, it is used a label:
lblTree.Text = stringHTML;
The tree is displayed using a dynamically constructed HTML string. The final string is 52 000 characters long. I don't think that is important, but I thought I would explain the background.
In aspx, it looks like this:
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align="left" class="PrintTBLHeader"><br />report as of 20/09/2012 : <br /><br /></td>
</tr>
<tr>
<td colspan="3"><br /><asp:Label runat="server" ID="lblTree"></asp:Label><br /><br /></td>
</tr>
<tr>
<td colspan="3" align="left" class="PrintTBLHeader"><br />2nd title:<br /><br /></td>
</tr>
<tr>
<td colspan="3"><br /><asp:Label runat="server" ID="lblMPMtree"></asp:Label></td>
</tr>
</table>
The problem is this:
when I open the print preview, it should say 6 pages (like in firefox and chrome - those are working right), but this print preview from IE8 is showing me only 3 pages.
lblTree is cut at the end of the 1st page
Then on the second page, instead of showing the rest of lblTree, it starts with the "2nd title" (tr #3 in the example above)
I found some article related to something like this, where the solution was adding media="print" to the <link>.
<link rel="stylesheet" type="text/css" href="..." media="print" />
That did not work.
To summarize:
Check the code if it's invalid to the DOCTYPE with the validator
If invalid, IE will render in quirksmode which is never a good thing.

Popup with 3 buttons - Onclick event problem AJAX , ASP.net project

For Save button, I have a popup which has 3 buttons inside., Yes, No and Cancel. Yes should call a function and update 2 tables in the database and No should update just one table and cancel should not make any changes in the page.
Used code for popup
<table id="pnlPopupMerchantUpdate" runat="server" style="display:none">
<tr>
<td>
<asp:Panel runat="server" CssClass="modalPopup">
<table width="350" height="80" class="warningPopup">
<tr>
<td>
<!-- <img src="images/warning_blue.gif" alt="Warning" /> -->
</td>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
Do you wish to update the Location Information as well.
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="btnYesMerchant" type="button" value="Yes" class="popupButton" causesvalidation="true" onclick="btnYessave_Click"/>
<input id="btnNoMerchant" type="button" value="No" class="popupButton" causesvalidation="true" onclick="btnNosave_Click" />
<input id="btnCancel" type="button" value="Cancel" class="popupButton"/>
</tr>
</table>
</asp:Panel>
</td>
</tr>
Here if the user clicks Yes it has to update Location info along with COmpany Info. If No is clicked, just Company Info. Cancel will not modify anything. There is a function UpdateMerchantInfo() which has to modify according to what is called, i mean yes or No.
I have used Onclick events for both Yes and NO but the problem here is, Yes should call its onclick event before getting into UpdatemerchantInfo(), the same way with NO.
In UpdateMerchantInfo(), i want to use if loop and do accordingly.
I hope i am clear!!
Thank you much!
You can use popup control extender in ajax. Will find more details Here
It has sufficient tags to suport your requirements.
You have to just create a contol(using tags) and in popup controlid set id of popup. Using this method you can define different eventhandlers.

Recaptcha ErrorMessage Property in ASP.NET

I am using recaptcha in an ASP.NET 3.5 application and for some odd reason the ErrorMessage property is not working. Below is my code
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="*******************************" PrivateKey="*******************" Theme="white" ErrorMessage="This is an typo error" />
When the typed text doesn't match with the recaptcha image text it still shows the default error message "Incorrect. Try again." instead of my custom error message. What could be the reason for this strange behavior
You put the message in a Literal tag. Here is my code snippet:
<tr>
<td align="center" colspan="2" >
<recaptcha:RecaptchaControl Theme="white" ID="recaptcha" runat="server" PrivateKey="*************"
PublicKey="*************" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False" Text="You have not entered the verification words correctly. Please try again."></asp:Literal>
</td>
</tr>
Mike

Resources