2

My html page is

<iframe runat="server" id="iframe1" width="100%" height="100%" scrolling="no"  frameborder="0"></iframe>

.cs content in my pageload event

iframe1.Attributes["src"] = "http://default.com/";
//iframe1.Attributes["height"] = "100%";
//iframe1.Attributes["width"] = "100%";
iframe1.Attributes.Add("style","width:100%;height:100%;");

But its not working

i want to display whole page content but my height of iframe is not taking the height of http://default.com/

Mitesh Jain
  • 555
  • 4
  • 13
  • 40

3 Answers3

1

I don't know how to autoresize iframe on .cs page but It's another option like put your iframe in datalist control like...

<asp:DataList ID="dtlhtml" runat="server" Width="100%">
    <ItemTemplate>
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td>
                    <iframe src='<%#Eval("html") %>' width="713" id="iframe1" 
                        frameborder="0" onLoad="autoResize 'iframe1');">
                    </iframe>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

Put javascript code as...

<script language="JavaScript">
function autoResize(id) 
{
    var newheight;
    var newwidth;
    if (document.getElementById(id))
    {
        newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
        newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
    }
    document.getElementById(id).height = (newheight) + "px";
    document.getElementById(id).width = (newwidth) + "px";
}
</script>

And put on .cs page.

DataTable dt1 = new DataTable();
dt1.Columns.Add("html");
DataRow dr = dt1.NewRow();
dr["html"] = "";//Any dynamic url path
dt1.Rows.Add(dr);
dtlhtml.DataSource = dt1;
dtlhtml.DataBind();

NOTE: This will not work in local host ..please try it on online.

Chris
  • 8,527
  • 10
  • 34
  • 51
Rajan Vachhani
  • 420
  • 3
  • 8
  • 17
0

I assume you don't want 'scrolling', so why not disable it?

<iframe src="/default.asp" width="100%" height="100%" scrolling="no"></iframe>

or try

iframe1.Attributes.Add("scrolling","no");

Edit: Try

PlaceHolder1.Controls.Add(new LiteralControl("<iframe src='mypage.aspx' width='100%' height='100%' scrolling='no'></iframe>"));

or

iframe1.Attributes["src"] = "http://www.asp.net";
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
  • I want to give src path on .cs page – Mitesh Jain Oct 05 '13 at 07:45
  • should i have to take PlaceHolder???and have to remove iframe from my html code?? – Mitesh Jain Oct 05 '13 at 07:59
  • Typically if you want to add controls to a page like you are doing then people use a placeholder and insert controls into it – Paul Zahra Oct 05 '13 at 08:11
  • Come to think of it, what exactly is iframe1 ? – Paul Zahra Oct 05 '13 at 08:13
  • Read this SO post http://stackoverflow.com/questions/9975810/make-iframe-automatically-adjust-height-according-to-the-contents-without-using – Paul Zahra Oct 05 '13 at 08:33
  • if the iframe src is given statically in html page than it will easily resize its page as javascript is call and seems the content of iframe src....but here all javascript is call before iframe get its src OR all javascript is call before it goes to page load so the javascript will not be helpfull for me – Mitesh Jain Oct 05 '13 at 08:38
  • Try adding the iframe during the PreRender event – Paul Zahra Oct 05 '13 at 08:41
0

Since you are using runat="server" so you can access the attributes like height and width from code behind. Try

Updated Answer

iFrame1.Attributes.Add("height","100%");
iFrame1.Attributes.Add("width","100%");
set scrolling ="no" inside tag as suggested by Paul