VB Programmer wrote:
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,
--
Joerg Jooss
www.joergjooss.de ne**@joergjooss.de