Passing querystring to iframe

Soldato
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
I thought this would be dead easy but no..... I need to embed a page inside another and pass the query string to it from the parent to the embedded page..

Querystring
Code:
?Tick_ID=ABC12345


Code:
<iframe id="MyIFrame" src="https://website.domain.com/info.asp?ticket_id=<%Tick_ID%>" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
I don't believe I need any code behind it but clearly I'm missing something as the string is not passed.

TIA!
 
Permabanned
Joined
9 Aug 2009
Posts
12,236
Location
UK
Code:
<iframe id="MyIFrame" src="https://website.domain.com/info.asp?ticket_id=<%=Request.QueryString["Tick_ID"]%>" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
Code:
<iframe id="MyIFrame" src="https://website.domain.com/info.asp?ticket_id=<%=Request.QueryString["Tick_ID"]%>" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
Code:
Parser Error Message: Server tags cannot contain <% ... %> constructs.
Hmmm, strange error. I'll continue to play ...

Replacing " with '
Code:
<iframe id="MyIFrame" src="https://website.domain.com/info.asp?ticket_id=<%=Request.QueryString['Tick_ID']%>" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
Renders the page but again not passing the querystring.
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
So to be clear, for my understanding. I have a selection gridview on one page which directs to another page on the same site with a querystring.
Code:
https://firstwebsite.domain.com/somepage?tick_id=ABC1234

Within somepage on the first site that which contains iframe to another source address where I wish to pass the querystring from the first.
Code:
<iframe id="MyIFrame" src="https://secondwebsite.domain.com/anotherpage?ticket_id=<%=Request.QueryString["tick_id"]%>" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
This should iframe to
Code:
https://secondwebsite.domain.com/anotherpage?ticket_id=ABC1234

The above should work? I'm getting myself in a right pickle with this. I've also now confused myself with "tick_id"; I may be incorrectly thinking the Request.QueryString requires "tick_id" to be defined in order it then passes the string "ABC1234".
 
Permabanned
Joined
9 Aug 2009
Posts
12,236
Location
UK
yeah it should work.

try just printing
<%=Request.QueryString["tick_id"]%>
to make sure the value has come through properly.

and try your iframe without passing it in just to make sure it doesn't error
<iframe id="MyIFrame" src="https://secondwebsite.domain.com/anotherpage?ticket_id=x" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>

and try passing it in like this:
<iframe id="MyIFrame" runat="server" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
<%
// may be syntax errors here, but you get the idea
// also note this sanitises input from the querystring, which is a vulnerability otherwise.
this.MyIFrame.Src = string.format("https://secondwebsite.domain.com/anotherpage?ticket_id={0}", int.parse(Request.QueryString["tick_id"]));
%>
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
Tried this quickly
Code:
<%=Request.QueryString["tick_id"]%>
which generates
Code:
Compiler Error Message: BC32017: Comma, ')', or a valid expression continuation expected.
:(

I'm off to Hoxton now so will likely pick this back up again tomorrow.

I much appreciate your support (and patience) with this!
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
OK; sorted it. Need to define it in code.
Code:
 'Declare variable in global scope
    Protected Tick_ID As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'set the value
        Tick_ID = Request.QueryString("Tick_ID")
    End Sub
Called via
Code:
 <iframe id="MyIFrame" src="https://website.domain.com/info.asp?ticket_id=<%=Tick_ID%>" scrolling="auto" width="100%" height="768px" frameborder="0"></iframe>
 
Back
Top Bottom