开发者

Embed an ASPX page into an ASCX Control?

Is it possible to embed an ASPX page into an ASCX con开发者_开发技巧trol?


No.

That would be a bit like building a car into the passenger seat.

-- Edit:

To be clear, you could potentially consider various ways of grabbing the content (such as actually requesting it) and then including it in your ASCX control, but it would, in general, but a quite "backwards" approach. What are you trying to do?


It is actually possible with iframe.

.ascx control code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Control.ascx.cs" Inherits="Project.Control" %>
<iframe id="ctrlIframe" runat="server" src="path/to/your_aspx_file.aspx"></iframe>

Iframe there links to aspx page.

You would also need to resize iframe to fit your aspx in ascx control:

<script type="text/javascript">
    window.onload = function IFrameFitContent() {
        var iframe = document.getElementById("<%= ctrlIframe.ClientID %>");
        var bHeight = iframe.contentWindow.document.body.scrollHeight;
        var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
        var bWidth = iframe.contentWindow.document.body.scrollWidth;
        var dWidth = iframe.contentWindow.document.documentElement.scrollWidth;
        var height = Math.max(bHeight, dHeight);
        var width = Math.max(dWidth, bWidth);
        iframe.height = height;
        iframe.width = width;
    }
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜