how to include aspx page in another aspx page? in asp.net - asp.net

I'm working on a custom web application and because I have many separate blocks I want to put them on a different page, I was wondering how can I include aspx content on existing page?
the reason I'm asking about aspx, and not custom web controls, is because I planned to use pagemethods on those separate pages.
Another reason is that I saw someone some saying we can do that, can't find the link now, so thought I'll try too, since it looks very neat:)
Thanks

Server.Execute (secondUrl) might do what you want. But UserControls are definitely more ASP.Net-ish :).

Based on what you describe, the proper answer is custom controls as they allow you to place the code anywhere on any page in an easily reusable manner.
Can you explain what you mean by "aspx content" - is that just html, is it controls? Also, what Page methods are you referring to?

Related

Add a master page programmatically

First off, I know this isn't a normal thing to do, so if it isn't possible, just let me know.
I have a bunch of pages (100+) that are all designed to be contained within an iframe. Recently, I've decided to move away from this and use a master page to do some formatting on the page that used to contain the iframe. However, in order to do this, the page inside the frame is now going to be the page that is navigated to. What I need to be able to do is apply this new master page to a page that didn't have a master page prior and I'd like to do it without having to change the markup of all the other pages. All of these pages inherit from a single parent class that can be used to accomplish this, if it is possible. It is necessary that iframes are not used in this solution, as their compatibility is part of the problem I'm trying to work around. Thanks for any help/ideas you can offer.
EDIT
This is the error I'm getting when I try the way the comments suggest:
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Should be very possible. As I recall, you can just have your base class set its own MasterPage in the OnPreInit event:
this.MasterPage = "~/SpecificMasterPage.aspx";
Response to comments
That complicates things. Here's something you can try, but I don't know whether it will work: try creating regular page to be your "master" page, and loading the other pages in as if they were controls using the Page.LoadControl method. I don't know whether whole pages can be loaded this way, and even if they are this is hacky at best, since you'll be producing new <html>, <head>, and <body> tags within the body of the page.
So your best bet is probably to convert all your pages to either use a MasterPage or to be Controls. If you're clever, you might be able to write a little program that can do this to all your pages automatically.

I don't want to render the form tag

I would really like to disable the rendering for the form tag. Basically asp.net will be providing read only pages which should be very clean. i.e, no form tags required
Take it out of the markup then. I don't think it's required if you're only providing read-only access. I'm able to create straight .aspx files on the web server without the form tag, and they work fine. Don't expect your postbacks to work, though.
Have you looked into ASP.NET MVC? It is designed for just this kind of thing...
ASP.NET WebForms does not work well without the main form (ViewState, PostBack, etc. will fail horribly). I think you may be using the wrong tool for your problem.
We have some read-only pages in a system, and we simply fetch the data from our DB as XML and apply an XSLT stylesheet to this. Might be overkill for you however.
Alternatively, why not just remove the tag? Or use an HTML page?

Partial rendering of an ASP.NET site

I have an ASP.NET application which calls aspx-pages in other ASP.NET applications (all on the same server and the same solution). This aspx-pages should be shown in a (fixed) region on the main-site in that way that that only the embedded pages is renewed, during user interactions there. Is an IFRAME the only way to achieve this goal, or can I use for example the AJAX update-panel or are there further possibilities / techniques. I have read something about the a control "UFRAME". Maybe this is the solution for my question !?!?
If you want to display a page within another page, you'll need to use frames or an i-frame. If you have access to all the code for these other ASPX pages though, it would probably be better to use User Controls (ASCX files) instead. You can then easily re-use these in as many pages as you like.

Is there a way to extend a class ASP session whenever an ASP .NET Request is made?

I have a web site that runs both classic ASP and ASP.NET Webforms. The sessions for each are separate.
I need to hit some asp page whenever a request is made on the ASP.NET pages.
Why? Because I need to extend the ASP's session so it doesn't expire.
I know this is going to cause a number of issues and I really really don't want to do this, but the decision is not in my hands, unfortunately.
Is there any way to accomplish what I'm trying to do?
Put a .asp page inside an iframe on the asp.net page? Just clarifying here... You don't need to make the iframe visible. 0px or whatever you want. But load it in the src= attribute.
Have a link to a do nothing ASP script file in the ASPX page? Or look at something like this.
Update- as you say you don't have master pages or anything like that. You could use an HttpModule to inject the extra HTML required to make the request to the classic ASP page. See here for an article on how to do that, or look at the code for this one. Creating one for your needs wouldn't be difficult. Find where you want to insert it and inject the extra HTML.
This might be a half cocked idea, but maybe on certain pages do a redirect to an asp page, then that page just redirects back to the calling asp.net page, I mean it all depends on what pages do what, but you can see where I am headed with this
Add a img tag to the page that targets one of the asp-pages in the application. Add a CSS class to the image that hides it and put something random or the current date in the query string so that it doesn't get cached, just to be on the safe side.

Conditional Display in ASPX Pages on Sharepoint

I wonder what the best practice for this scenario is:
I have a Sharepoint Site (MOSS2007) with an ASPX Page on it. However, I cannot use any inline source and stuff like Event handlers do not work, because Sharepoint does not allow Server Side Script on ASPX Pages per default.
Two solutions:
Change the PageParserPath in web.config as per this site
<PageParserPaths>
<PageParserPath VirtualPath="/pages/test.aspx"
CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
Create all the controls and Wire them up to Events in the .CS File, thus completely eliminating some of the benefits of ASP.net
I wonder, what the best practice would be? Number one looks like it's the correct choice, but changing the web.config is something I want to use sparingly whenever possible.
So in that case I would wrap it up in a feature and deploy it via a solution. This way I think you will avoid the issue you are seeing. This is especially useful if you plan to use this functionality within other sites too.
You can also embed web parts directly in the page, much like you do a WebControl, thereby avoiding any gallery clutter.
What does the ASPX page do? What functionality does it add? How are you adding the page into the site? By the looks of it this is just a "Web Part Page" in a document library.
I would have to do a little research to be 100%, but my understanding is that inline code is ok, providing it's in a page that remains ghosted, and thereby trusted. Can you add your functionality into the site via a feature?
I would avoide option 1, seems like bad advice to me. Allowing server side code in your page is a security risk as it then becomes possible for someone to inject malicious code. Sure you can secure the page, but we are talking remote execution with likely some pretty serious permissions.
Thanks so far. I've successfully tried Andrew Connel's solution:
http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx
Wrapping it into a solution is part of that, but the main problem was how to get the code into that, and it's more leaning towards Option 2 without having to create the controls in code.
What I was missing:
In the .cs File, it is required to manually add the "protected Button Trigger;" stuff, because there is no automatically generated .designer.cs file when using a class library.
Well, it's a page that hosts user controls. It's a custom .aspx Page that will be created on the site, specially because I do not want to create WebParts.
It's essentially an application running within Sharepoint, utilizing Lists and other functions, but all the functionality is only useful within the application, so flooding the web part gallery with countless web parts that only work in one place is something i'd like to avoid.

Resources