1.配合 Menu 操作 iframe 內容
Asp.Net menu: 重點在 target 目標為 iframe 的 name 值
1 |
<span style="color: #0000ff"><</span><span style="color: #800000">asp:Menu</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Menu1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #0000ff"><</span><span style="color: #800000">Items</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #0000ff"><</span><span style="color: #800000">asp:MenuItem</span> <span style="color: #ff0000">NavigateUrl</span><span style="color: #0000ff">="target_url"</span> <span style="color: #ff0000">Target</span><span style="color: #0000ff">="iframe1"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="target"</span> |
1 |
<span style="color: #ff0000">Value</span><span style="color: #0000ff">="target"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:MenuItem</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #0000ff"></</span><span style="color: #800000">Items</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #0000ff"></</span><span style="color: #800000">asp:Menu</span><span style="color: #0000ff">></span> |
Asp.Net iframe: 一定要輸入 name 值
1 |
<span style="color: #0000ff"><</span><span style="color: #800000">IFRAME</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="iframe1"</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="iframe1"</span> <span style="color: #ff0000">src</span><span style="color: #0000ff">="default.html"</span> <span style="color: #ff0000">scrolling</span><span style="color: #0000ff">="auto"</span> <span style="color: #ff0000">runat</span>=<span style="color: #ff0000">server</span> |
1 |
<span style="color: #ff0000">height</span><span style="color: #0000ff">="500"</span> <span style="color: #ff0000">width</span><span style="color: #0000ff">="700"</span><span style="color: #0000ff">></span> |
1 |
/IFRAME<span style="color: #0000ff">></span> |
2.動態變更內容
同上 , 拉一個 iframe 進aspx 頁面裡
C# Page_Load 加入以下指令
1 |
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e) |
1 |
{ |
1 |
HtmlControl iframe1 = (HtmlControl)<span style="color: #0000ff">this</span>.FindControl(<span style="color: #006080">"iframe1"</span>); |
1 |
} |
在需要動態變更頁面的地方添加:
1 |
iframe1.Attributes[<span style="color: #006080">"src"</span>] = <a href="http://yourserver">http://yourserver</a>; |
動態變更 iframe 尺寸
1 |
iframe1.Attributes[<span style="color: #006080">"width"</span>] = <span style="color: #006080">"500px"</span>; |
1 |
iframe1.Attributes[<span style="color: #006080">"height"</span>] = <span style="color: #006080">"500px"</span>; |
(Visited 60 times, 1 visits today)