Webform Server.execute not displaying executed form

Hello,
I have an asp webform called default.aspx  and a 2nd called webform1.aspx.  After logging in with default I would like to call webform1 multiple times from default.aspx  passing Session variables back and forth. To test this I created a simple web application with my two forms as shown below:

Server.Execute calls webform1.aspx but the webform1 page does not display. It returns to the line after the server.execute statement after executing. I need the webform1 page to display each time it is called so that I can accept inputs. Can some let me know what I am doing wrong?

regards
Pat
 

default.aspx.cs
   public partial class _Default : Page
    {
        string status="active";
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
                while(status == "active")
                {
                    Server.Execute("~/WebForm1.aspx");
                }
        }

webform1.aspx.cs
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            return;
        }
    }
LVL 1
pclarke7Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

try changing this and see you are not in the recursive with while loop.

while(status == "active")
{
        Server.Execute("WebForm1.aspx");
}
pclarke7Author Commented:
Hi Lokesh,
doesn't make any difference. WebForm1 gets called and I can break in page_load of Webform1 but control returns to Default.aspx rather than displaying the Webform1 page. If I use Server.Transfer then webform1 page is displayed however the default.aspx page is closed and therefore I cannot return. Any other ideas why the page is executed but will not display ?

regards
Pat
Lokesh B RDeveloperCommented:
Hi,

How are you returning back to the default.aspx page?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

pclarke7Author Commented:
I have a button defined in WebForm1.aspx page as follows

protected void Button1_Click(object sender, EventArgs e)
 {
     return;
 }


The idea being that when the Webform1 page displayed the user would click button 1 to return to the default.aspx page. However because the page is not displayed control seems to return to Default.aspx after page_Load of Webform1 completes.

regards
Pat
pclarke7Author Commented:
Hi Lokesh,
I have been searching for answers to this issue. Couple of things were highlighted.

 1. Fact that the new page is opened in the same form as the calling one means that the page loaded flag of the 1st form applies to the 2nd. - this may be preventing 2nd page from loading.
 2. recommendation to set enableViewStateMAC="false"

Neither of these seem to make any difference. Do you know of any other way of achieving the following logic without using Server.Execute  

After successfully Logging into to website I need to iterate through a transaction calling a new webpage each time an input is required.  Once the required input has been entered in this new webpage I need to return to the iteration to pick up the next transaction statement.


 If you can suggest any way of doing this without using "Server.Execute", I would be very grateful

regards
Pat
Lokesh B RDeveloperCommented:
Hi,

You can use Server.Transfer

 string status = "active";
      
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            while (status == "active")
            {
                Server.Transfer("WebForm1.aspx");
            }
        }

Open in new window



public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Server.Transfer("default.aspx");
        }
    }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pclarke7Author Commented:
Hi Lokesh,
 I can't use Server.Transfer since this closed down the default.aspx. I need default.aspx to remain open since it contains the  looping logic controlling the calls to WebForm1.aspx Plus I only want to display the default.aspx page once. Doing a Server.Transfer back to default.aspx will restart the process from the begining each time.

regards
Pat
pclarke7Author Commented:
old question - resolved long time ago
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.