Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Saturday, March 31, 2012

sensible way to pass around values

With .NET 1.x, this is what I did. On the destination page
public class ToWebForm : System.Web.UI.Page
{
public const string PARAMETER = "PARAM";
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
Response.Write(paramFromAnotherPage);
}
}
}
And on the source page
Context.Items.Add(ToWebForm.PARAMETER, "value");
Server.Transfer("ToWebForm.aspx");
Basically I am creating an interface (not in a .net sense) on the
destination page so that the source page can simply use the string
constant as the name of the parameter.
.NET 2.0 does not seem to be happy with this. The funny thing is,
sometimes it works, and sometimes it does not even compile, which I
find very frustrating.
Is there any reason why this won't work well with partial classes?
And what is the sensible way to pass values from page to page without
having to copy and past the parameter names all over the web project?..NET 2.0 is "last page aware". Try this:
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
****************************************
********
Think outside the box!
****************************************
********
"David C" <profnachos@.gmail.com> wrote in message
news:1186434005.231509.3920@.z24g2000prh.googlegroups.com...
> With .NET 1.x, this is what I did. On the destination page
> public class ToWebForm : System.Web.UI.Page
> {
> public const string PARAMETER = "PARAM";
> protected void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
> Response.Write(paramFromAnotherPage);
> }
> }
> }
> And on the source page
> Context.Items.Add(ToWebForm.PARAMETER, "value");
> Server.Transfer("ToWebForm.aspx");
> Basically I am creating an interface (not in a .net sense) on the
> destination page so that the source page can simply use the string
> constant as the name of the parameter.
> .NET 2.0 does not seem to be happy with this. The funny thing is,
> sometimes it works, and sometimes it does not even compile, which I
> find very frustrating.
> Is there any reason why this won't work well with partial classes?
> And what is the sensible way to pass values from page to page without
> having to copy and past the parameter names all over the web project?
>
On Aug 7, 6:20 am, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@.comcast.netNoSpamM> wrote:
> .NET 2.0 is "last page aware". Try this:http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
>
Thank you very much. I was pleasantly surprised to see that it even
reads the ViewState of the previous page.
Is there anyway to enable this for a gridview? Perhaps a user control or a
hidden button?
Ross
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamM> wrote in
message news:%234TxnWP2HHA.3940@.TK2MSFTNGP05.phx.gbl...
> .NET 2.0 is "last page aware". Try this:
> http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com
> Co-author: Microsoft Expression Web Bible (upcoming)
> ****************************************
********
> Think outside the box!
> ****************************************
********
> "David C" <profnachos@.gmail.com> wrote in message
> news:1186434005.231509.3920@.z24g2000prh.googlegroups.com...
>

sensible way to pass around values

With .NET 1.x, this is what I did. On the destination page

public class ToWebForm : System.Web.UI.Page
{
public const string PARAMETER = "PARAM";
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
Response.Write(paramFromAnotherPage);
}
}
}

And on the source page
Context.Items.Add(ToWebForm.PARAMETER, "value");
Server.Transfer("ToWebForm.aspx");

Basically I am creating an interface (not in a .net sense) on the
destination page so that the source page can simply use the string
constant as the name of the parameter.

..NET 2.0 does not seem to be happy with this. The funny thing is,
sometimes it works, and sometimes it does not even compile, which I
find very frustrating.

Is there any reason why this won't work well with partial classes?

And what is the sensible way to pass values from page to page without
having to copy and past the parameter names all over the web project?..NET 2.0 is "last page aware". Try this:
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"David C" <profnachos@.gmail.comwrote in message
news:1186434005.231509.3920@.z24g2000prh.googlegrou ps.com...

Quote:

Originally Posted by

With .NET 1.x, this is what I did. On the destination page
>
public class ToWebForm : System.Web.UI.Page
{
public const string PARAMETER = "PARAM";
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
Response.Write(paramFromAnotherPage);
}
}
}
>
And on the source page
Context.Items.Add(ToWebForm.PARAMETER, "value");
Server.Transfer("ToWebForm.aspx");
>
Basically I am creating an interface (not in a .net sense) on the
destination page so that the source page can simply use the string
constant as the name of the parameter.
>
.NET 2.0 does not seem to be happy with this. The funny thing is,
sometimes it works, and sometimes it does not even compile, which I
find very frustrating.
>
Is there any reason why this won't work well with partial classes?
>
And what is the sensible way to pass values from page to page without
having to copy and past the parameter names all over the web project?
>


On Aug 7, 6:20 am, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@.comcast.netNoSpamMwrote:

Quote:

Originally Posted by

.NET 2.0 is "last page aware". Try this:http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
>
>


Thank you very much. I was pleasantly surprised to see that it even
reads the ViewState of the previous page.
Is there anyway to enable this for a gridview? Perhaps a user control or a
hidden button?

Ross

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamMwrote in
message news:%234TxnWP2HHA.3940@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

.NET 2.0 is "last page aware". Try this:
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
>
************************************************
Think outside the box!
************************************************
"David C" <profnachos@.gmail.comwrote in message
news:1186434005.231509.3920@.z24g2000prh.googlegrou ps.com...

Quote:

Originally Posted by

>With .NET 1.x, this is what I did. On the destination page
>>
>public class ToWebForm : System.Web.UI.Page
>{
>public const string PARAMETER = "PARAM";
>protected void Page_Load(object sender, System.EventArgs e)
>{
>if (!IsPostBack)
>{
>string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
>Response.Write(paramFromAnotherPage);
>}
>}
>}
>>
>And on the source page
> Context.Items.Add(ToWebForm.PARAMETER, "value");
> Server.Transfer("ToWebForm.aspx");
>>
>Basically I am creating an interface (not in a .net sense) on the
>destination page so that the source page can simply use the string
>constant as the name of the parameter.
>>
>.NET 2.0 does not seem to be happy with this. The funny thing is,
>sometimes it works, and sometimes it does not even compile, which I
>find very frustrating.
>>
>Is there any reason why this won't work well with partial classes?
>>
>And what is the sensible way to pass values from page to page without
>having to copy and past the parameter names all over the web project?
>>


>
>

Thursday, March 22, 2012

Serious cache problem - Page_Load get never get called !

Hi,
I got a asp.net page that stores session variable.
This page gets input parameter by QueryString and this variable stored
into session variable.
Asp.net page works in normal navigation scenario.
Then I bookmarked this url to my favorites and call this url by
clicking favorites link.
When in this situation, at initial time Page_Load() of my asp.net gets
called but after first time, page never get called by clicking
favorites link.
I guess maybe IE caches the link and read it when user clicks from
favorite link.
I've tried below codes only to fail to call Page_Load(). All of them
failed.
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
Navigating my asp.net pages by favorites link is very possible user
scenario.
This is unavoidable.
How can I always ensure IE to read URL from Web Server not from cache
when user clicks favorites link?
Any suggestion will be appreciated. TIA. :)
Regards,
RyanAppending the header doesn't necessarily tell the browser not to cache the
page. For that, your best bet is to include the appropriate meta tag: <META
HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the meta tag may help catch
more browsers than just the response header alone.
You might also try using a Response.Flush() right after you send the pragma
header. I've seen that help in some instances.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Ryan Park" <bajy@.intizen.com> wrote in message
news:5016f0aa.0501030540.572182a1@.posting.google.com...
> Hi,
> I got a asp.net page that stores session variable.
> This page gets input parameter by QueryString and this variable stored
> into session variable.
> Asp.net page works in normal navigation scenario.
> Then I bookmarked this url to my favorites and call this url by
> clicking favorites link.
> When in this situation, at initial time Page_Load() of my asp.net gets
> called but after first time, page never get called by clicking
> favorites link.
> I guess maybe IE caches the link and read it when user clicks from
> favorite link.
> I've tried below codes only to fail to call Page_Load(). All of them
> failed.
> Response.Expires = 0;
> Response.Cache.SetNoStore();
> Response.AppendHeader("Pragma", "no-cache");
> Navigating my asp.net pages by favorites link is very possible user
> scenario.
> This is unavoidable.
> How can I always ensure IE to read URL from Web Server not from cache
> when user clicks favorites link?
> Any suggestion will be appreciated. TIA. :)
> Regards,
> Ryan
Mark Fitzpatrick wrote:
> Appending the header doesn't necessarily tell the browser not to
> cache the page.
That's correct -- the HTTP spec distinguishes between caches and histories.
For histories, Cache-Control and such do not apply.

> For that, your best bet is to include the appropriate
> meta tag: <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the
> meta tag may help catch more browsers than just the response header
> alone.
But only if the browser's HTTP implementation stinks. Out of curiosity: Can
you name any modern browser for which a META tag works, but a HTTP header
doesn't?
Cheers,
Joerg Jooss
www.joergjooss.de
news@.joergjooss.de

Serious cache problem - Page_Load get never get called !

Hi,

I got a asp.net page that stores session variable.

This page gets input parameter by QueryString and this variable stored
into session variable.

Asp.net page works in normal navigation scenario.

Then I bookmarked this url to my favorites and call this url by
clicking favorites link.

When in this situation, at initial time Page_Load() of my asp.net gets
called but after first time, page never get called by clicking
favorites link.

I guess maybe IE caches the link and read it when user clicks from
favorite link.

I've tried below codes only to fail to call Page_Load(). All of them
failed.

Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");

Navigating my asp.net pages by favorites link is very possible user
scenario.

This is unavoidable.

How can I always ensure IE to read URL from Web Server not from cache
when user clicks favorites link?

Any suggestion will be appreciated. TIA. :)

Regards,
RyanAppending the header doesn't necessarily tell the browser not to cache the
page. For that, your best bet is to include the appropriate meta tag: <META
HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the meta tag may help catch
more browsers than just the response header alone.

You might also try using a Response.Flush() right after you send the pragma
header. I've seen that help in some instances.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Ryan Park" <bajy@.intizen.com> wrote in message
news:5016f0aa.0501030540.572182a1@.posting.google.c om...
> Hi,
> I got a asp.net page that stores session variable.
> This page gets input parameter by QueryString and this variable stored
> into session variable.
> Asp.net page works in normal navigation scenario.
> Then I bookmarked this url to my favorites and call this url by
> clicking favorites link.
> When in this situation, at initial time Page_Load() of my asp.net gets
> called but after first time, page never get called by clicking
> favorites link.
> I guess maybe IE caches the link and read it when user clicks from
> favorite link.
> I've tried below codes only to fail to call Page_Load(). All of them
> failed.
> Response.Expires = 0;
> Response.Cache.SetNoStore();
> Response.AppendHeader("Pragma", "no-cache");
> Navigating my asp.net pages by favorites link is very possible user
> scenario.
> This is unavoidable.
> How can I always ensure IE to read URL from Web Server not from cache
> when user clicks favorites link?
> Any suggestion will be appreciated. TIA. :)
> Regards,
> Ryan
Mark Fitzpatrick wrote:
> Appending the header doesn't necessarily tell the browser not to
> cache the page.

That's correct -- the HTTP spec distinguishes between caches and histories.
For histories, Cache-Control and such do not apply.

> For that, your best bet is to include the appropriate
> meta tag: <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the
> meta tag may help catch more browsers than just the response header
> alone.

But only if the browser's HTTP implementation stinks. Out of curiosity: Can
you name any modern browser for which a META tag works, but a HTTP header
doesn't?

Cheers,

--
Joerg Jooss
www.joergjooss.de
news@.joergjooss.de

Serve a file on page load (save file as)

Hi,
I'm trying to do something fairly simple. I want to create a web page that
will take a parameter in the URL and return a file on page load. The file is
stored in a MSSQL 2005 database in an XML field (which is similar to a
varchar(max) field). The URL would look something like this:
http://www.mydomain.com/myspecialpage/?MyTableID=99
99 being the value for primary key of the table, and the XML file would come
from the XML field in that record. When the user loads such a URL in a
browser, he/she would be prompted to save that file on disk. Could someone
point me in the right direction? I've looked for examples on how to do this,
but had no luck so far. BTW, I'm more familiar with C# than VB. I've set up
a SqlDataSource on my page, and that works fine. I tested it with a GridView
and I can see the contents of my XML field. Obviously, I don't wnt that page
to display anything. I juat want to return the XML field content as a file
to save.
Thank you,
Alain Quesnel
alainsansspam@dotnet.itags.org.logiquel.com
www.logiquel.comHi Alain,
The task at hand is fairly simple:
You need two pages:
1. The main page with html content with "invisible" iframe
2. aspx page serving XML files
The reason for that is diffrent types of MIME content cannot be mixed on a
single page.
1. ASPX Page user is redirected to get the file:
-- begin MyPage.aspx code --
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"
Inherits="MyPage" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
asjdhajskdhaskjdhasdha dsaj hdkasjdh sahd
<iframe src="http://pics.10026.com/?src=<%= ResolveUrl("~/File.aspx?MyTableID=") +
Request.QueryString["MyTableID"] %>"
width="0" marginheight="0" marginwidth="0" scrolling="no" style="width:
0px;
height: 0px"></iframe>
blah blah...
<table>
<tr>
<td>
Some content</td>
<td>
More content...</td>
</tr>
</table>
</div>
</form>
</body>
</html>
-- end MyPage.aspx code --
2. Page referenced in src attribute of the iframe tag allowing user to
download the file or displaying javascript error dialog box if file cannot b
e
found.
-- begin File.aspx code --
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="File.aspx.cs"
Inherits="File" %>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var queryStringValue = '<%= Request.QueryString["MyTableID"] %>';
if (queryStringValue != '')
{
alert('Could not find file with ID = "' + queryStringValue + '"');
}
</script>
</body>
</html>
-- end File.aspx code --
-- begin File.aspx.cs behind/beside code --
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class File : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int id;
if (int.TryParse(Request.QueryString["MyTableID"], out id))
{
string xml = GetXML(id);
if (xml != null)
{
Response.Clear();
Response.ContentType = "xml";
Response.AddHeader("Content-Disposition", "attachment;
filename=whatever.xml");
Response.Write(xml);
Response.End();
}
}
}
private string ConnectionString
{
get
{
// currently connection string is read from web.config
// but it may be replaced with a constant value
// i.e return
" server=myserverName;database=dbName;uid=
userId;pwd=secretPassword"
return
ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].Connectio
nString;
}
}
private string GetXML(int id)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
string query = "SELECT [XML] FROM [MyTable] WHERE MyTableID = @.id";
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
command.Parameters.Add("@.id", SqlDbType.Int).Value = id;
return Convert.ToString(command.ExecuteScalar());
}
}
}
}
-- end File.aspx.cs behind/beside code --
Done. You should be fine from this point. There are few little things
missing as i didn't want to confuse you at this stage (i.e. if XML content i
s
big we should use sequential access instead).
Hope this helps
--
Milosz
"Alain Quesnel" wrote:

> Hi,
> I'm trying to do something fairly simple. I want to create a web page that
> will take a parameter in the URL and return a file on page load. The file
is
> stored in a MSSQL 2005 database in an XML field (which is similar to a
> varchar(max) field). The URL would look something like this:
> http://www.mydomain.com/myspecialpage/?MyTableID=99
> 99 being the value for primary key of the table, and the XML file would co
me
> from the XML field in that record. When the user loads such a URL in a
> browser, he/she would be prompted to save that file on disk. Could someone
> point me in the right direction? I've looked for examples on how to do thi
s,
> but had no luck so far. BTW, I'm more familiar with C# than VB. I've set u
p
> a SqlDataSource on my page, and that works fine. I tested it with a GridVi
ew
> and I can see the contents of my XML field. Obviously, I don't wnt that pa
ge
> to display anything. I juat want to return the XML field content as a file
> to save.
>
> --
> Thank you,
> Alain Quesnel
> alainsansspam@.logiquel.com
> www.logiquel.com
>
>
Wow! This is beyond my wildest dreams. I can't wait to try this out. I'll
let you know how it all works out.
Thank you,
Alain Quesnel
alainsansspam@.logiquel.com
www.logiquel.com
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:BC9D74C4-E0E7-488F-B5E7-390E2A111DAE@.microsoft.com...
> Hi Alain,
> The task at hand is fairly simple:
> You need two pages:
> 1. The main page with html content with "invisible" iframe
> 2. aspx page serving XML files
> The reason for that is diffrent types of MIME content cannot be mixed on a
> single page.
> 1. ASPX Page user is redirected to get the file:
> -- begin MyPage.aspx code --
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"
> Inherits="MyPage" %>
> <!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>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> asjdhajskdhaskjdhasdha dsaj hdkasjdh sahd
> <iframe src="http://pics.10026.com/?src=<%= ResolveUrl("~/File.aspx?MyTableID=") +
> Request.QueryString["MyTableID"] %>"
> width="0" marginheight="0" marginwidth="0" scrolling="no" style="width:
> 0px;
> height: 0px"></iframe>
> blah blah...
> <table>
> <tr>
> <td>
> Some content</td>
> <td>
> More content...</td>
> </tr>
> </table>
> </div>
> </form>
> </body>
> </html>
> -- end MyPage.aspx code --
> 2. Page referenced in src attribute of the iframe tag allowing user to
> download the file or displaying javascript error dialog box if file cannot
> be
> found.
> -- begin File.aspx code --
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="File.aspx.cs"
> Inherits="File" %>
> <html>
> <head>
> <title></title>
> </head>
> <body>
> <script type="text/javascript">
> var queryStringValue = '<%= Request.QueryString["MyTableID"] %>';
> if (queryStringValue != '')
> {
> alert('Could not find file with ID = "' + queryStringValue + '"');
> }
> </script>
> </body>
> </html>
> -- end File.aspx code --
> -- begin File.aspx.cs behind/beside code --
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Linq;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> using System.Xml.Linq;
> using System.Data.SqlClient;
> public partial class File : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> int id;
> if (int.TryParse(Request.QueryString["MyTableID"], out id))
> {
> string xml = GetXML(id);
> if (xml != null)
> {
> Response.Clear();
> Response.ContentType = "xml";
> Response.AddHeader("Content-Disposition", "attachment;
> filename=whatever.xml");
> Response.Write(xml);
> Response.End();
> }
> }
> }
> private string ConnectionString
> {
> get
> {
> // currently connection string is read from web.config
> // but it may be replaced with a constant value
> // i.e return
> " server=myserverName;database=dbName;uid=
userId;pwd=secretPassword"
> return
> ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].Connect
ionString;
> }
> }
> private string GetXML(int id)
> {
> using (SqlConnection connection = new SqlConnection(ConnectionString))
> {
> string query = "SELECT [XML] FROM [MyTable] WHERE MyTableID = @.id";
> using (SqlCommand command = new SqlCommand(query, connection))
> {
> connection.Open();
> command.Parameters.Add("@.id", SqlDbType.Int).Value = id;
> return Convert.ToString(command.ExecuteScalar());
> }
> }
> }
> }
> -- end File.aspx.cs behind/beside code --
> Done. You should be fine from this point. There are few little things
> missing as i didn't want to confuse you at this stage (i.e. if XML content
> is
> big we should use sequential access instead).
> Hope this helps
> --
> Milosz
>
> "Alain Quesnel" wrote:
>
Works great. I'll have to make a few adjustments, but I'm glad it works.
Thank you,
Alain Quesnel
alainsansspam@.logiquel.com
www.logiquel.com
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:BC9D74C4-E0E7-488F-B5E7-390E2A111DAE@.microsoft.com...
> Hi Alain,
> The task at hand is fairly simple:
> You need two pages:
> 1. The main page with html content with "invisible" iframe
> 2. aspx page serving XML files
> The reason for that is diffrent types of MIME content cannot be mixed on a
> single page.
> 1. ASPX Page user is redirected to get the file:
> -- begin MyPage.aspx code --
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"
> Inherits="MyPage" %>
> <!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>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> asjdhajskdhaskjdhasdha dsaj hdkasjdh sahd
> <iframe src="http://pics.10026.com/?src=<%= ResolveUrl("~/File.aspx?MyTableID=") +
> Request.QueryString["MyTableID"] %>"
> width="0" marginheight="0" marginwidth="0" scrolling="no" style="width:
> 0px;
> height: 0px"></iframe>
> blah blah...
> <table>
> <tr>
> <td>
> Some content</td>
> <td>
> More content...</td>
> </tr>
> </table>
> </div>
> </form>
> </body>
> </html>
> -- end MyPage.aspx code --
> 2. Page referenced in src attribute of the iframe tag allowing user to
> download the file or displaying javascript error dialog box if file cannot
> be
> found.
> -- begin File.aspx code --
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="File.aspx.cs"
> Inherits="File" %>
> <html>
> <head>
> <title></title>
> </head>
> <body>
> <script type="text/javascript">
> var queryStringValue = '<%= Request.QueryString["MyTableID"] %>';
> if (queryStringValue != '')
> {
> alert('Could not find file with ID = "' + queryStringValue + '"');
> }
> </script>
> </body>
> </html>
> -- end File.aspx code --
> -- begin File.aspx.cs behind/beside code --
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Linq;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> using System.Xml.Linq;
> using System.Data.SqlClient;
> public partial class File : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> int id;
> if (int.TryParse(Request.QueryString["MyTableID"], out id))
> {
> string xml = GetXML(id);
> if (xml != null)
> {
> Response.Clear();
> Response.ContentType = "xml";
> Response.AddHeader("Content-Disposition", "attachment;
> filename=whatever.xml");
> Response.Write(xml);
> Response.End();
> }
> }
> }
> private string ConnectionString
> {
> get
> {
> // currently connection string is read from web.config
> // but it may be replaced with a constant value
> // i.e return
> " server=myserverName;database=dbName;uid=
userId;pwd=secretPassword"
> return
> ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].Connect
ionString;
> }
> }
> private string GetXML(int id)
> {
> using (SqlConnection connection = new SqlConnection(ConnectionString))
> {
> string query = "SELECT [XML] FROM [MyTable] WHERE MyTableID = @.id";
> using (SqlCommand command = new SqlCommand(query, connection))
> {
> connection.Open();
> command.Parameters.Add("@.id", SqlDbType.Int).Value = id;
> return Convert.ToString(command.ExecuteScalar());
> }
> }
> }
> }
> -- end File.aspx.cs behind/beside code --
> Done. You should be fine from this point. There are few little things
> missing as i didn't want to confuse you at this stage (i.e. if XML content
> is
> big we should use sequential access instead).
> Hope this helps
> --
> Milosz
>
> "Alain Quesnel" wrote:
>