Wednesday, March 21, 2012

Passing XML as parameter to Web page

I must be missing something, because this should be easy to do.

After the user has selected several options on a page, I do a database query
which returns a few records that I want to pass to another page via XML. How
do I do this?

I typically Response.Redirect around my app, including various parameters.
Do I just include the XML as a parameter as in:
Response.Redirect("page.aspx?" & ds.WriteXML)

That just doesn't seem right.

If you would be so kind as to include both what the sending and receiving
should be doing in any example it would be greatly appreciated!So you have a page, "Page1" which captures some criteria, and then performs
a database query, and passes those results to "Page2" for display.

If it's a particularly small amount of XML, I suppose you could use the
query string, though you want to encode your querystring;

Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))

But that seems like a particularly risky way to use a querystring.

It makes more sense to me collect your criteria in Page1, then pass the
actual query parameters to Page2, and have Page2 do the query itself. In
most cases the query params will take much less space to transmit than the
query results. Also it makes Page2 more generally usable [barring special
security concerns].

Another option is to do the query, cache either the query or the result in
the database, and then pass the queryID to Page2. That's a useful approach
for very large complex queries, especially if you want to keep a history of
queries a user has run. I use that for real-estate sites, where the user
can have hundreds of criteria, and the broker needs to know what the
customer is searching for.

/// M

"Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> I must be missing something, because this should be easy to do.
> After the user has selected several options on a page, I do a database
query
> which returns a few records that I want to pass to another page via XML.
How
> do I do this?
> I typically Response.Redirect around my app, including various
parameters.
> Do I just include the XML as a parameter as in:
> Response.Redirect("page.aspx?" & ds.WriteXML)
> That just doesn't seem right.
> If you would be so kind as to include both what the sending and receiving
> should be doing in any example it would be greatly appreciated!
Can you use "Session"? You can store XML as DOM object or string in Session,
and pass Session state to next page, or next of next page. Session is a
popular way to carry data to next page in ASP.NET.

Shaw

"MWells" wrote:

> So you have a page, "Page1" which captures some criteria, and then performs
> a database query, and passes those results to "Page2" for display.
> If it's a particularly small amount of XML, I suppose you could use the
> query string, though you want to encode your querystring;
> Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
> But that seems like a particularly risky way to use a querystring.
> It makes more sense to me collect your criteria in Page1, then pass the
> actual query parameters to Page2, and have Page2 do the query itself. In
> most cases the query params will take much less space to transmit than the
> query results. Also it makes Page2 more generally usable [barring special
> security concerns].
> Another option is to do the query, cache either the query or the result in
> the database, and then pass the queryID to Page2. That's a useful approach
> for very large complex queries, especially if you want to keep a history of
> queries a user has run. I use that for real-estate sites, where the user
> can have hundreds of criteria, and the broker needs to know what the
> customer is searching for.
> /// M
>
> "Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
> news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> > I must be missing something, because this should be easy to do.
> > After the user has selected several options on a page, I do a database
> query
> > which returns a few records that I want to pass to another page via XML.
> How
> > do I do this?
> > I typically Response.Redirect around my app, including various
> parameters.
> > Do I just include the XML as a parameter as in:
> > Response.Redirect("page.aspx?" & ds.WriteXML)
> > That just doesn't seem right.
> > If you would be so kind as to include both what the sending and receiving
> > should be doing in any example it would be greatly appreciated!
>
Thank you both for your responses. I guess you confirmed my suspicions: you
can't pass a stream as the parameter. I will have to pass the text.

I didn't say it in my original post, but there are a couple of reasons I
can't just do the query in Page2. 1) The database query must be kept
independent from the processing due to manipulation of the data and the fact
the data may be coming from multiple sources. 2) Page2 may be on a
different server. 3) Page2 is actually a few different pages, so the desire
is that the query done in Page1 passes common data to subsequent pages.

...Steve

"Shaw" wrote:

> Can you use "Session"? You can store XML as DOM object or string in Session,
> and pass Session state to next page, or next of next page. Session is a
> popular way to carry data to next page in ASP.NET.
> Shaw
>
> "MWells" wrote:
> > So you have a page, "Page1" which captures some criteria, and then performs
> > a database query, and passes those results to "Page2" for display.
> > If it's a particularly small amount of XML, I suppose you could use the
> > query string, though you want to encode your querystring;
> > Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
> > But that seems like a particularly risky way to use a querystring.
> > It makes more sense to me collect your criteria in Page1, then pass the
> > actual query parameters to Page2, and have Page2 do the query itself. In
> > most cases the query params will take much less space to transmit than the
> > query results. Also it makes Page2 more generally usable [barring special
> > security concerns].
> > Another option is to do the query, cache either the query or the result in
> > the database, and then pass the queryID to Page2. That's a useful approach
> > for very large complex queries, especially if you want to keep a history of
> > queries a user has run. I use that for real-estate sites, where the user
> > can have hundreds of criteria, and the broker needs to know what the
> > customer is searching for.
> > /// M
> > "Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
> > news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> > > I must be missing something, because this should be easy to do.
> > > > After the user has selected several options on a page, I do a database
> > query
> > > which returns a few records that I want to pass to another page via XML.
> > How
> > > do I do this?
> > > > I typically Response.Redirect around my app, including various
> > parameters.
> > > Do I just include the XML as a parameter as in:
> > > Response.Redirect("page.aspx?" & ds.WriteXML)
> > > > That just doesn't seem right.
> > > > If you would be so kind as to include both what the sending and receiving
> > > should be doing in any example it would be greatly appreciated!

0 comments:

Post a Comment