Is it possible to load .ascx page in iframe - c#

Is it possible to load ascx page in iframe.When I try it I got a error
The type of page you have requested is not served because it has been explicitly forbidden. The extension '.ascx' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
But when I want to load .html page in same location it can be load.
May i did any thing wrong ?Thanks.

You can't load .ascx file in an iframe for the same reason you can't load it directly in the browser. It's not a page, but rather a control. So it's meant to be used within an .aspx page.

ascx is for usercontrols.
It isn't supported to request an ascx you have to create a page (aspx) for it. Another approach is to create an HttpHandler and manipulate the response.

.ascx-file is not a page it is a user control. What you need to do is either make a page of it, that is, an .aspx-file and change it accordingly, or wrap it in an .aspx-file that includes your .ascx-file.

Related

Getting Current Page URL From Master Page with Routing

I'm trying to be able to determine which page url the user is loading from the master page.
So far I've been able to use
this.Request.RawUrl
to get the path of the page itself, which works fine for most cases.
However in this particular website, we use a lot of complicated routing, so something like (say)
/Product/5/2/Purchase
might redirect to /Purchase.aspx?ID=5Type=2
of which I'd want the actual aspx file path.
I've also tried this.Request.PhysicalPath, but that doesn't give the route and basically just appends the path the user requested to the virtual directory.
So how can I do it?
An asp.net Page treats a master page as just another control.
So if you want to get the page, you can always use the Page property provided by the MasterPage class.
I used this and worked :
Page.ToString().Replace("ASP.","").Replace("_",".")

ASP.net, VS 2010, C# -- how to find a control on a different page?

I have a FormView on Default.aspx page. I have BLL_Census.cs class in App_Code folder. I want to set properties of textbox on FormView on Default page from BLL_Census.cs but don't know how to reference of find the FormView on the other page from within BLL_Census.cs.
It will be easier if you place the value from BLL_census.cs into session variable and access it when other page is rendered in the browser
A page only "exists" when the browser call it
So It's not possible to access another page from the current page.
If you need to share page area, use Page Controls
If you need to share data, use the Asp.NET Session
are you using website project? try web application project

Opening an external page inside our page

I used to implement this above title by using iframe but now I dont want to use it any more I have some plans in my mind I need to implement them by opening an external page inside our asp.net page without using any iframe I have only simple aspx page with div tage and panel and some other serverside componants, I just want to know how I can do it without iframe ? I don't want to design new complex control but I am looking for some methods can do that for me.
I have to mention that I need to control area which is loaded by external site as the same as iframe but the difference is that iframe can not handled by ajax even you put iframe inside the update panel your page has refresh and postback while you are changing the src value programmatically (in c# code) so we have to design some others methods what is the solution ?
I thought I can make request an get some html and show into div but I couldn't to implement it.
You could
Make a WebRequest on the server-side and then set the div's text to HTML returned
You could make an invisible iFrame to make the request and then use JavaScript to grab the HTML from the iFrame and put it in a DIV. (EDIT: Comment suggests this won't work)
You can't generally make calls (like XmlHttpRequest) to external websites because of cross-site scripting issues.
Your direct request, "opening an external page inside our asp.net page without using any iframe" is not possible, by design.
You mention AJAX. You can use AJAX to load your page, remove the headers (or do that serverside) and replace the <body> tag with a <div> tag (or do that server side too). This way, you can place the contents of your page anywhere you like. As a container, I suggest you use a block level element, a <div> would suffice.
The only (!) problem here is: cross-site requests like this are not honored by browsers. You can solve this server-side by loading the page from elsewhere using WebRequest or similar means.
Depends on where you'd like to merge the data. If you'd like to merge the data on the client browser, your only other option besides frames is to use Javascript/Ajax.
You can do a jQuery.ajax() on page load and use the html() method on a div to populate it with the textual result of that AJAX call.
Try to use as little of the WebForms control hierarchy and life-cycle as possible. It sounds like your problem can be fixed with AJAX if you don't mind the second request on page load.
If you would like to merge the content on the server side ( rarely the right thing to do ) you can use System.Net.HttpWebRequest to get and merge the data before returning it to the browser.
there's no substitute for an iframe in your situation. you're not going to be able to make ajax requests to the other site due to security concerns. you could retrieve the contents of a single page server side and render it to the client but none of the functionality will be included, since the content is now running in the context of your own site.

Using Admin Panel How we can create a aspx page in sitefinity?

how we can create the dynamic page ex. help.aspx and write the code in sitefinity. Because i facing a problem I create a page but i unable to know in which directory the page is lived. If any one help me Suggest.
http://abc.com/sitefinity/admin/pages.aspx
I'm not exactly sure I understand your question correctly. When you create a page in Sitefinity, it doesn't create an ASPX file. The data for the page is kept in the database and served from there. There are no physical files involved.
If you want to write some code that executes when a page loads, you have two options:
Put the code into a control and drop the control on a page created from within Sitefinity
Create a regular ASPX page from Visual Studio and include it as an external page in Sitefinity.
I would recommend the first option, as this would provide you with all the Sitefinity goodness that all pages use - templates, editing through the browser, etc.
If you wanted something else and I misunderstood, please be more specific.
Slavo, The Sitefinity Team

Dynamic Page Creation .aspx

I have a IHttpModule to serve up .aspx page dynamically, this is so I can pack them into a DLL and drop it into an existing web site and serve up my pages.
I have a class MyPage derived from System.Web.UI.Page which has a .aspx, .aspx.cs and a aspx.designer.cs file.
When I try to instantiate the class I.e. MyPage myNewPage = MyPage(), all of the child controls are null...
I then attempt to render that page output using Server.Execute(myNewPage) in the BeginRequest event of the IHttpModule.
I know I can compile the page and use reflector to get the compiled class that's built out, but is there a cleaner way to do this?
Or even a better approach to what I'm doing?
Thanks,
Goosey
I don't think this is possible. You cannot just instantiate page like any other object. What you need "might" be a VirtualPathProvider.
I'm not sure it's the best solution, but you can embed all the aspx pages into your dll as assets. On request extract the aspx from the embedded resource and write to disk (if it hasn't already happened).
There may be a way to provide the aspx from the embedded resource without actually writing to disk, but I don't know for sure.
aspx has some intimate relationship with ASP.NET runtime. I do not think that instantiating it bu just calling constructor is a good idea. What you can do instead is to have an empty (standard) aspx and move your code to user controls - ascx
Those you can load dynamically using LoadControl method

Categories