博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Loading pages in IFRAME dynamically from codebehind - ASP.NET

Posted on 2008-09-09 09:43  LonelyStar  阅读(214)  评论(0)    收藏  举报

Loading pages in IFRAME dynamically from codebehind - ASP.NET

 

 

The workaround to do that is as follows:-

1. Specify the "runat=server" attribute as follows in the ASPX Page:-

<IFRAME id="frame1" scrolling="auto" runat="server">
</IFRAME>

2. In the codebehind, you may need to declare a HtmlGenericControl in the control declarations section as follows:-

C#
protected System.Web.UI.HtmlControls.HtmlGenericControl frame1;
 
VB.NET
Protected WithEvents frame1 As System.Web.UI.HtmlControls.HtmlGenericControl 3. Then, you need to do a findcontrol to identify the control on the page and typecast it as follows:-
C#
HtmlControl frame1 = (HtmlControl)this.FindControl("frame1"); 
 
VB.NET
Dim frame1 As HtmlControl = CType(Me.FindControl("frame1"), HtmlControl)

Note: You can have different name for the Generic Control you define in the code behind, but for ease I keep both the same. The "frame1" referred in Find Control is the ID as declared in the ASPX Page.

4. Thereafter, you will be able to access the src property as follows:-

 
C#
frame1.Attributes["src"] = http://www.live.com/ ;

 
VB.NET
frame1.Attributes("src") = http://www.live.com/ ;

 
iframe 标签 -- 代表HTML内联框架
  • iframe标签是成对出现的,以<iframe>开始,</iframe>结束
  • 属性
    • name -- 定义了内容页名称,此名称在框架页内链接时使用到
    • src -- 定义了内容页URL
    • frameborder -- 定义了内容页的边框,取值为(1|0),缺省值为1
      • 1 -- 在每个页面之间都显示边框
      • 0 -- 不显示边框
    • marginwidth -- 定义了框架中HTML文件显示的上下边界的宽度,取值为px,缺省值由浏览器决定
    • marginheight -- 定义了框架中HTML文件显示的左右边界的宽度,取值为px,缺省值由浏览器决定
    • scrolling -- 定义是否有滚动条,取值为(yes|no|auto),缺省值为auto
      • yes -- 显示滚动条
      • no -- 不显示滚动条
      • auto -- 当需要时再显示滚动条
    • align -- 垂直或水平对齐方式
    • height -- 框架的高度
    • width -- 框架的宽度
  • 引用网址:http://www.dreamdu.com/xhtml/tag_iframe/