uhu
uhu

Reputation: 1742

Embed an ASPX page into an ASCX Control?

Is it possible to embed an ASPX page into an ASCX control?

Upvotes: 3

Views: 1164

Answers (2)

Turbcool
Turbcool

Reputation: 114

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>

Upvotes: 0

Noon Silk
Noon Silk

Reputation: 55082

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?

Upvotes: 2

Related Questions