开发者

How to call/execute another ASP.net page from the parent ASP.Net page without disrupting the flow of events?

When a button/link is clicked, I want this URL to be called followed by the execution of the following statements.

The ASP.Net page is in C# btw.

Function A
   statement A
   call abc.apsx
   statement B

abc.aspx is a silent page, doesn't display开发者_StackOverflow中文版 anything on the page but creates an output.txt file. So when abc.aspx is called, output.txt file is created and Statement B is executed seamlessly. Hope I made sense.

I have no .Net programming knowledge. Please help me.

Thank you..


You can create a HttpWebRequest object to call abc.apsx page

e.g.

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://host/abc.apsx");

or Using WebClient to fire a request to the web page.

   WebClient client = new WebClient ();

        // Add a user agent header in case the 
        // requested URI contains a query.
        // important to add user-agent to emulate a real request from browser. 
        client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

        Stream data = client.OpenRead ("http://host/abc.apsx");
        StreamReader reader = new StreamReader (data);
        string s = reader.ReadToEnd ();
        Console.WriteLine (s);
        data.Close ();
        reader.Close ();

http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx


This is exactly what HttpServerUtility.Execute is for.


Why are you having the abc.aspx act as a standalone page?

From how your question reads, you're goal is to get the Output.Txt file, thus, why not have a class that builds that output.txt file as a separate object which your initial page can call?

And then, if you need it accessible to the user, have abc.aspx call this class as well.

Or you can go with codemeit's suggestion of the httpwebreques (which if abc.aspx is on a separate domain this is probably your best course of action)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜