having an asp back button in popup window for displaying pdf - c#

Am having a popup window for displaying pdf.. but i need to put an asp button in pop up window have tried the following code but could not find a solution.. can any one resolve this?
enter code here
<asp Page attributes>
...............
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<br />
<form id="form1" runat="server">
<div> <asp:Button ID="dd" runat="server" OnClick="Backonclick" Text="back"/>
</div>
<div></div>
</form>
</body>
</html>
on page load event
dd.Visible = true;
string path = Request.QueryString["val"].ToString();
string extention = Path.GetExtension(path);
int len = extention.Length - 1;
string extwithoutdot = extention.Substring(1, len);
if (extwithoutdot.Equals("JPG") || extwithoutdot.Equals("jpg") ||
extwithoutdot.Equals("jpeg") || extwithoutdot.Equals("JPEG"))
{
extwithoutdot = "jpeg";
...........

The issue here is that you're mixing two separate types of documents; a PDF is one type of download, whilst an HTML is another. A single download can't unfortunately be both, and you can't switch document types part-way through and expect the browser to handle it.
The simplest solution for what you're after is to combine the two on the client side. Load your pop-up as an HTML page (generated by ASP.NET if you wish) and include within that an IFRAME linking to your PDF generation script; something of the form:
<html>
<body>
<a class='button' href="javascript:window.close()">Close</a>
<iframe src="generatePdf.aspx" height="300" width="300" />
</body>
</html>

i have got solution
<form id="form1" runat="server">
<iframe src="Copy (2) of DisplayPdf.aspx" width="1000" height="400">
</iframe>
<iframe src="Copy of DisplayPdf.aspx" width="100" height="200">
</iframe>
</form>

Related

asp:Button how to capture Response.WriteLine

I am using the OnClick of the asp:Button tag to compute a report which I would like to display as an innerHTML of a div tag. I would like to use the Response.WriteLine method to return this html file. Does ASP.NET webforms provide a way of capturing this response?
Am I forced to use JavaScript instead? I am using C# on the Server side.
The Web Forms way of doing this is to use a control and set its InnerHTML from the code behind. Here's a self contained example:
<%#Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected void GenerateReport(object sender, EventArgs e)
{
var reportHTML = "<p>This is a <span style='font-weight: bold;'>report!</span></p>";
ReportDiv.InnerHtml = reportHTML;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<form runat="server">
<asp:Button runat="server" OnClick="GenerateReport" Text="Generate Report" />
<div runat="server" id="ReportDiv"></div>
</form>
</body>
</html>

How to show multiple HTML contents in a single page in ASP.Net?

Suppose I'm opening email details in a ASP.Net .aspx page div control. The problem is when I'm opening an email details containing html tag the page is showing messed up. Only the inner html contents are showing on the page. Is there any way I could solve this problem.
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form >
<!-- Outer HTML contents... -->
<div id="dvViewMailReadOnly" style="overflow:auto; width:100%;height:auto;">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<img src="http://click.email.skype...>
</body>
</html>
</div>
</form>
</body>
</html>
The email contents are showing on dvViewMailReadOnly dynamically.
I'm still not sure I understand the problem. Yes, the HTML is invalid, as there must only be one <html> element (and consequently also only one <head> and <body> element).
If you are allowed to modify your form, then you could simply do this:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form >
<!-- Outer HTML contents... -->
<div id="dvViewMailReadOnly" style="overflow:auto; width:100%;height:auto;">
<img src="http://click.email.skype...">
</div>
</form>
</body>
</html>
Replace < by < and > by >

Download a Word editable document from an aspx page

I currently have an aspx page returning a html form (with images and css). I would like get a download Word editable version of this form without rewrite all the code. Is it possible ?
An example : I Have a page 'WebForm2.aspx' with a simple content like this.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="WebApplication15.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Title</h1>
<asp:CheckBox runat="server" ID="myTest" Text="Doc 1" /><br />
<asp:CheckBox runat="server" ID="myTest2" Text="Doc 2" /><br />
<asp:CheckBox runat="server" ID="myTest3" Text="Doc 3" /><br />
<asp:CheckBox runat="server" ID="myTest4" Text="Doc 4" /><br />
</div>
</form>
</body>
</html>
I would like that from an other page for example a button that lets you download the contents of 'WebForm2.aspx' in an editable Word document.
I Add this in Page_PreRender method
Response.AddHeader("Content-Type", "application/msword");
It's partially work. If I save the document css and images aren't loaded but if I only open the downloadable content css and images are loaded.
MS Word can edit html document so by adding Content-Type=application/msword record in header will make browser open your page in browser unfortunately without css and images.
Add following code in prerender event on your page
Response.AddHeader("Content-Type", "application/msword");

Open Pdf in new tab

On Button Click I generate a PDF file and then open it at client side with:
Response.ContentType = "application/pdf";
Response.TransmitFile(path);
This will show the pdf in the browser, but in the same tab. How can I open it in a new tab?
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language=vbscript>
sub OpenInNewWindow()
window.open("PDFContainer.aspx")
end sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Way 3</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type=button OnClick="OpenInNewWindow()" value="Open in New Window"/>
<br /><br />
This time, we will open a new Internet Explorer Window and Show the PDF File directly in the IE
</div>
</form>
</body>
</html>
You cannot do this from the server side. It is a client side operation. see Create a new tab or window for a web page from ASP.NET

Dispay html textbox with value from code behind using c#

How can I display an html textbox with value obtained from code behinh?
As long as your string value is not private, you should be able to do something like this
<input type="text" value="<%= YourStringValue %>" />
You could use an actual <asp:Textbox /> and set it's "text" value directly from the code behind. If you want to directly inject text into a "normal" html textbox (or anywhere else for that matter), you can use <%= SomeValue %>. Yet another way is to include the "runat=server" attribute on standard html elements, allowing you to manipulate them from the codebehind.
Normally I'd just go for the built-in ASP textbox control so I don't have to worry about persisting values/wiring up viewstate/etc. Injecting dynamic content into plain html elements tends to be an edge case requirement...
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
//assign text value here
txt1.Value = "hello world!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="txt1" runat="server" type="text" />
</div>
</form>
</body>
</html>

Categories

Resources