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");
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:-
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/ ;
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),缺省值为autoyes-- 显示滚动条no-- 不显示滚动条auto-- 当需要时再显示滚动条
align-- 垂直或水平对齐方式height-- 框架的高度width-- 框架的宽度
- 引用网址:http://www.dreamdu.com/xhtml/tag_iframe/
浙公网安备 33010602011771号