By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Programmatically creating pages

P: n/a
Is there a way to instantiate a page object in code and redirect the response to it? I know that this is how the actual ASP.NET engine ultimately does it under the covers. However, is this available to the developer? I want to be able to use page inheritance to create a centralized page controler without the need to build .aspx files for every page (since they would be pretty much empty shells anyway).

Here is a sample of what I "want" to do. However, the Response.Redirect() method currently only takes a string argument and does not accept a page object reference

MyPage myPage = new MyPage()
Response.Redirect(myPage); <---- this does not work. I wish that it would

Any ideas
Thanks
Matt
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Probably not since there is a lot more then creating a page instance, such
as creating a request and response object for the page, extracting cookies,
parsing querystrings, etc. Might as well write your own web server.

Question, with your desired behavior, how is the browser going to get the
HTML content. Unless you page objects stream the content through the
Response.Write method, you pages will not be able to display since the
code-behind does not contain the actual markup. You say that you do not
want any ASPX files, but that is where the markup is located.

If you want, you can create a sight with no ASPX files at all but rather use
an HttpHandler to intercept any ASPX calls which could then stream the
desired markup to the browser.

"mslyh" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Is there a way to instantiate a page object in code and redirect the response to it? I know that this is how the actual ASP.NET engine ultimately
does it under the covers. However, is this available to the developer? I
want to be able to use page inheritance to create a centralized page
controler without the need to build .aspx files for every page (since they
would be pretty much empty shells anyway).
Here is a sample of what I "want" to do. However, the Response.Redirect() method currently only takes a string argument and does not accept a page
object reference.
MyPage myPage = new MyPage();
Response.Redirect(myPage); <---- this does not work. I wish that it would!
Any ideas?
Thanks,
Matt

Nov 18 '05 #2

P: n/a
Matt,

If your .aspx file would only be empty shells (i.e. no meaningful HTML) then
you don't need pages. Instead of actual pages create a lot of different
classes (one for each page you would have created with the logic specific to
that "page") derived from one of Control, WebControl, UserControl, or
similar classes.

Instead of redirecting to another page you controler class needs to
instantiate the appropriate control class and let it process (probably need
to add it to the controller object's Controls collection).

Eran
"mslyh" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Is there a way to instantiate a page object in code and redirect the response to it? I know that this is how the actual ASP.NET engine ultimately
does it under the covers. However, is this available to the developer? I
want to be able to use page inheritance to create a centralized page
controler without the need to build .aspx files for every page (since they
would be pretty much empty shells anyway).
Here is a sample of what I "want" to do. However, the Response.Redirect() method currently only takes a string argument and does not accept a page
object reference.
MyPage myPage = new MyPage();
Response.Redirect(myPage); <---- this does not work. I wish that it would!
Any ideas?
Thanks,
Matt

Nov 18 '05 #3

P: n/a
To achieve what you are looking for you need to look at Context.Rewritepath
method and an HttpModule to pass control of the request to the page that you
specify in the rewritepath method. see
http://msdn.microsoft.com/library/de...epathtopic.asp

We have a Content management system
http://www.3internet.co.uk/products/inigo.aspx that does exactly what you
mention using this method. A site using our cms typically uses less than 10
templates to serve all page content, when the page is requested the path
relates to content stored in sql database which also contains details of
which template to use. In the HttpModule the request is then forwarded
using the Context.Rewritepath method to the template specified. This has
the big added bonus of allowing pages to be served without the need for
lengthy querystrings, all pages having static looking urls, which really
does make a difference in search engine positioning.

Good Luck

Matt
http://www.3internet.com
"Eran Amitai" <er********@hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
Matt,

If your .aspx file would only be empty shells (i.e. no meaningful HTML) then you don't need pages. Instead of actual pages create a lot of different
classes (one for each page you would have created with the logic specific to that "page") derived from one of Control, WebControl, UserControl, or
similar classes.

Instead of redirecting to another page you controler class needs to
instantiate the appropriate control class and let it process (probably need to add it to the controller object's Controls collection).

Eran
"mslyh" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Is there a way to instantiate a page object in code and redirect the response to it? I know that this is how the actual ASP.NET engine

ultimately does it under the covers. However, is this available to the developer? I
want to be able to use page inheritance to create a centralized page
controler without the need to build .aspx files for every page (since they
would be pretty much empty shells anyway).

Here is a sample of what I "want" to do. However, the
Response.Redirect() method currently only takes a string argument and does not accept a page
object reference.

MyPage myPage = new MyPage();
Response.Redirect(myPage); <---- this does not work. I wish that it

would!

Any ideas?
Thanks,
Matt


Nov 18 '05 #4

P: n/a
Thanks to all that answered. There were some really great ideas presented and many of them will actually acomplish what I want to do. I will do some more research on the implications of each method to decide which one will be best in my situation

Thanks again for all of the great options
Mat

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.