Interact with forms programmatically

R

Ray Booysen

Hi all

I have a webform with some functionality I need to use. But I need the
page to render first. Is there any way to do this?

I essentially need to instanciate an instance of the page get it to
render without it showing on the screen and then call a method that is
available.

Can this be done?

Regards
Ray
 
V

Vadivel Kumar

Ray said:
woops, forgot to mention. This is with ASP.net 1.1

Hi,

If i assume that you need to execute that page internally and get the ht
ml content, then it is very much possible. In the bottom of this reply
you can find and excerpt that calls the .aspx page using WebRequest
object and populates the html content into Div element.

In other way, if i assume that you want to execute the page just for the
sake of doing some process and with you need to pass some parameters
(means, you have to input some values) for the methods. Then, the only
way is to encapsulate the class that is inherited by the page from
another class and calling its methods to do so.

But, I suggest you should keep the code that needed to be "re-used" for
multi-purpose should be kept in different class and should be called in
appropriate places whenever needed.

Anyways, Let me know if this helps you or I am wrong in any case. And,
check the below code excerpt as well.

-
Vadive

-------
1. Create an ASPX page called "another_domain_info.aspx"
2. The below is the code that goes in the .aspx file

<body>
<form id="form1" runat="server">
<div id="yahooHtml" runat="Server"></div>
</form>
</body>

3. Now, in the another_domain_info.aspx.cs file create Page_Load event
and put the below code.

protected void Page_Load(object sender, EventArgs e)
{

WebRequest w = WebRequest.Create("http://www.yahoo.com");
WebResponse wr = w.GetResponse();

StreamReader r = new StreamReader (wr.GetResponseStream());

String html = r.ReadToEnd();

HtmlGenericControl DivElement = this.FindControl("yahooHtml")
as HtmlGenericControl;
DivElement.InnerHtml = html;

r.Close();
wr.Close();
}

4. Now press F5 to execute this code. You can see yahoo's home page in
the aspx file.

Basically, what happens is WebRequest object request the given url and
gets the response coming back from the server. After getting the
response we are binding the response which is html data to the div tag
kept in the .aspx file.
 
R

Ray Booysen

Argh, I expected the Webrequest to be executed within the current
context, and it seems to create a new session and execute seperately.

I'm calling a page within my application. Is there any way to call the
page within the current context?

Regards
Ray
 
R

Ray Booysen

YAY! Server.Execute was what I needed! :)

Ray said:
Argh, I expected the Webrequest to be executed within the current
context, and it seems to create a new session and execute seperately.

I'm calling a page within my application. Is there any way to call the
page within the current context?

Regards
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top