How get Request.Querystring from IFrame page

V

VB Programmer

I have an ASPX page that is used for content. I have a master page which
sticks the page in an IFrame.

Question: From the content/ASPX page, I can't seem to reference
request.querystring. Any way around this? I need to read it.

Thanks!
 
J

Joerg Jooss

VB said:
I have an ASPX page that is used for content. I have a master page
which sticks the page in an IFrame.

Question: From the content/ASPX page, I can't seem to reference
request.querystring. Any way around this? I need to read it.

The "outer" page should be constructed in such a way that it appends the
query string to the IFRAME's target URL.

Cheers,
 
V

VB Programmer

How do I do that?

Joerg Jooss said:
The "outer" page should be constructed in such a way that it appends the
query string to the IFRAME's target URL.

Cheers,
 
J

Joerg Jooss

VB said:
How do I do that?

Make the IFRAME a HtmlControl and append Request.QueryString to the IFRAME's
"src" attribute in the outer page's code behind class.

Cheers,
 
V

VB Programmer

Any examples of how to do this? Thanks!

Joerg Jooss said:
Make the IFRAME a HtmlControl and append Request.QueryString to the
IFRAME's "src" attribute in the outer page's code behind class.

Cheers,
 
J

Joerg Jooss

VB said:
Any examples of how to do this? Thanks!

Here's the code-behind class for a Web Form with an IFRAME HTML control with
an ID "iframe", that shows how to append the Web Form's query string to the
IFRAME's src attribute:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApp {
/// <summary>
/// Zusammenfassung für IFrameDemo.
/// </summary>
public class IFrameDemo : System.Web.UI.Page {
protected System.Web.UI.HtmlControls.HtmlGenericControl iframe;

private void Page_Load(object sender, System.EventArgs e) {
this.iframe.Attributes["src"] += UrlEncodedQueryString;
}

private string UrlEncodedQueryString {
get {
ICollection keys = Request.QueryString.Keys;
StringBuilder builder = new StringBuilder("?", 2048);
foreach (string key in keys) {
builder.AppendFormat("{0}={1}&", key,
HttpUtility.UrlEncode(
Request.QueryString[key],
Encoding.UTF8));
}
// This will either cut the ? for empty query strings
// or the surplus & for non-empty ones. Just makes the
// query string look nice all the time ;-)
builder.Length -= 1;

return builder.ToString();
}
}

// Cut generated code...
}

As you can see, it's trivial. The interesting part was providing a means to
URL encode the query string again (there seems to be no method in the FCL
that works on an existing query string without escaping & or ? as well).

Note that this sample assumes the query string's URL encoding is UTF-8
based.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top