I have a page that I need to call from another page more that one time. The important thing is to execute the Page_Load method. the first page have this code (The first page name is Call.aspx):
Dim objWebClient As New WebClient
objWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
Dim objStream As Stream = objWebClient.OpenRead("D:\confirm.aspx")
Dim objSR As New System.IO.StreamReader(objStream)
objWebClient.Dispose()
objStream.Dispose()
This should call the other page. It does not execute the other page. I have the following code to make sure that the confirm page is executed:
Dim objWrite As New System.IO.StreamWriter("c:\aa.txt")
objWrite.WriteLine("Hello")
objWrite.Close()
But there is no output. Any ideas?
What is this doing?:
Is
D:\a reference to a web address? It looks like you’re just calling the file itself, which isn’t going to have the effect you’re looking for. (Ignoring for a moment the file residing in the root of a drive…)ASPX pages aren’t executable in and of themselves. A web server (IIS, usually) has to handle the requests for them and pass those requests through the .NET runtime, etc., in order to handle the server-side processing. The file itself is just text, it has no internal means to interpret server-side code. That’s what a web server is for.
In order to make a web request to a web resource (a page, or any other web resource), you need to use a web URL. Something like:
http://localhost/confirm.aspxSo that page will need to be served somewhere by a web server.More to the point, however, is the fact that you shouldn’t have to do this. If code needs to be shared by two pages, that code should be extracted into a shared component. A “page” should never have to “call another page” (unless they’re on completely separate servers and you’re going for more of a SOA approach). Both pages should call a single shared component (a class, usually, maybe in its own assembly or just in the web project that has the pages).
Business logic doesn’t go in pages. Only UI goes in pages. Shared business logic goes in business classes.