简体   繁体   中英

Dynamically Add iFrame to a Page?

I need to generate a composite page made up of other pages in our system.

Is it possible for me to dynamically add iFrames to a page, each with its own src pointing to different URLs which are determined on the fly? If so, is there a preferred method to this?

Otherwise I need to refactor the other pages into user controls so I can add them as needed.

Although I'd seriously consider revising your pages to usercontrols if you'd like the "pages" to interact with each other. But for the question itself: you could add LiteralControls to your page (containing the iFrames) or to a placeholder.

PlaceHolder1.Controls.Add(new LiteralControl("<iframe src='mypage.aspx'></iframe>"));

您可以像动态添加任何.net控件一样在页面上执行此操作,但是您需要添加HtmlGenericControl

You could use the Document Object Model (DOM) / Javascript [1,2] to add iframes to your page. If you'd better like c# you'll have to postback before modifying the document I think (I'm not an expert in c# / asp).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM