You can't directly do what it is you're trying to do but here's a work
around:
In your WebForm2, add code like this:
WebForm1 wf1 = (WebForm1)Context.Handler;
That will make WebForm1 available to the page you called with
Server.Execute. Now, in WebForm1, create an image control with its visible
property set to false, or even an array to hold the information you want to
copy. Set the protection of the image control to public.
Create a property to return the image:
public System.Web.UI.WebControls.Image MyImage
{
get { return Image1; }
set { Image1 = value; }
}
If you choose to use an array to get the values into, create a public
property in WebForm1 to return the array value:
private object imagePropertyValues[];
public object ImagePropertyValues[]
{
get { return imagePropertyValues; }
set { imagePropertyValues = value; }
}
In the code of your WebForm2, copy the properties you wish back to the
WebForm1 control or WebForm1 array. You can also copy the image object,
itself:
wf1.MyImage = Image1; // this line is in WebForm2.aspx.cs
That will let you retrieve property values back in WebForm1 but will not let
you dynamically control the values in WebForm2. If you want to dynamically
control the values in WebForm2, then create public properties or objects in
WebForm1 to hold those values prior to calling Server.Execute("WebForm2").
Then in the code for WebForm2, retrieve those values from the WebForm1
object you created in the first line of code above.
It's only slightly convoluted but you can, by using these concepts, set
values in WebForm2 and use those values in WebForm1 after WebForm2 completes
execution.
The one thing you cannot do is to change a value in WebForm2 controls after
WebForm2 returns. Think of WebForm2 as a method, and when it completes
execution, its fields are out of scope and cannot be accessed.
Dale