Targeting an <IFRAME> in code

  • Thread starter Thread starter carlos.cruz
  • Start date Start date
C

carlos.cruz

Hi,

I manage to open a PDF file in an <IFRAME> by "clicking" on an HyperLink
with:

HyperLink.NavigateURL = "file:///C:\file.pdf"
HyperLink.Target = "iframename"

The question is... How can I do the same thing by "clicking" on a
button????

I searched in the System.Web.UI.HtmlControls collection and I can't find
the IFRAME object...

Any ideas?

Thanks in advance
CC
 
An IFRAME is simply HTML in a Page:

<iframe src ="/something.aspx"></iframe>

Add a runat=server to it, and an HtmlGeneric Control behind it, if you want
to manipulate it programmatically.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hi,

I'm sorry but I don't undertand what you mean by putting a generic html
control behind the iframe. Could you be more specific?

Thanks
CC
 
Every Control (that is part of the Page definition) in the Page Template has
a corresponding object declaration in the CodeBehind class. In this case,
you would have to add it yourself. What software are you using to develop
your app?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hello Carlos
This is how you can set the SRC attribute of your IFRAME
Please find the code below

---code behind which excecutes when you click the button---
private void ButtonSearch_Click(object sender, System.EventArgs e

string sText = TextBoxSearch.Text
HtmlGenericControl ctl = (HtmlGenericControl) Page.FindControl("SiteSearchResult")
ctl.Attributes["Src"] = "SiteSearchResult.aspx?sText="+sText;


--- IFRAME definition begin --
<iframe runat="server" id="SiteSearchResult" name="SiteSearchResult" frameborder="no" height="100% width="100%"></iframe

--- Search Button and search text box begin ----
<asp:textbox id="TextBoxSearch" Width="72px" runat="server"></asp:textbox><asp:button id="ButtonSearch" runat="server" Text="Search"></asp:button

Hope this helps

Reza Nabi
 
Back
Top