Interact with forms programmatically

Discussion in 'ASP .Net' started by Ray Booysen, Jun 27, 2006.

  1. Ray Booysen

    Ray Booysen Guest

    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
     
    Ray Booysen, Jun 27, 2006
    #1
    1. Advertising

  2. Ray Booysen

    Ray Booysen Guest

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

    Ray Booysen wrote:
    > 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
     
    Ray Booysen, Jun 27, 2006
    #2
    1. Advertising

  3. Ray Booysen wrote:
    > woops, forgot to mention. This is with ASP.net 1.1
    >
    > Ray Booysen wrote:
    >> 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


    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.
     
    Vadivel Kumar, Jun 27, 2006
    #3
  4. Maybe Server.Execute will help?

    "Ray Booysen" <> wrote in message
    news:...
    > woops, forgot to mention. This is with ASP.net 1.1
    >
    > Ray Booysen wrote:
    >> 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
     
    Mark Newmister, Jun 27, 2006
    #4
  5. Ray Booysen

    Ray Booysen Guest

    Hi Vadivel

    Thanks a ton, this is exactly what I'm looking for. :)

    Vadivel Kumar wrote:
    > Ray Booysen wrote:
    >> woops, forgot to mention. This is with ASP.net 1.1
    >>
    >> Ray Booysen wrote:
    >>> 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

    >
    > 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.
     
    Ray Booysen, Jun 27, 2006
    #5
  6. Ray Booysen

    Ray Booysen Guest

    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

    Vadivel Kumar wrote:
    > Ray Booysen wrote:
    >> woops, forgot to mention. This is with ASP.net 1.1
    >>
    >> Ray Booysen wrote:
    >>> 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

    >
    > 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.
     
    Ray Booysen, Jun 28, 2006
    #6
  7. Ray Booysen

    Ray Booysen Guest

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

    Ray Booysen wrote:
    > 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
    >
    > Vadivel Kumar wrote:
    >> Ray Booysen wrote:
    >>> woops, forgot to mention. This is with ASP.net 1.1
    >>>
    >>> Ray Booysen wrote:
    >>>> 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

    >>
    >> 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.
     
    Ray Booysen, Jun 28, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    381
    KathyB
    Jul 4, 2003
  2. lltaylor
    Replies:
    1
    Views:
    400
    Steve C. Orr [MVP, MCSD]
    Jun 30, 2004
  3. =?Utf-8?B?RGljazIwMDQ=?=

    how does the freetextbox interact with other html elements??

    =?Utf-8?B?RGljazIwMDQ=?=, Nov 3, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    364
    =?Utf-8?B?RGljazIwMDQ=?=
    Nov 3, 2004
  4. Steve
    Replies:
    10
    Views:
    698
    Steve
    Jul 13, 2005
  5. Eric
    Replies:
    2
    Views:
    607
Loading...

Share This Page