Topic: Navigation - Using the Execute method
Share/Save/Bookmark
Navigating using the "EXECUTE" method
 
Use the "Server" object's "Execute" method to process a second Web form without leaving the first Web form. This technique lets
you direct the results from a Web form to a region on the current page. As with the "Transfer" method, "Execute" requires
that the Web form's "EnableViewStateMac" attribute be set to "False" to disable "ViewState" hashing.
 
Example: The following line shows how to disable hashing so that a page's ViewState can be used from another page:
Add this to first Web Form's HTTP code
                       v------------------------v
<%@ Page language="C#" EnableViewStateMac="false" Codebehind="RedirectNTransfer.aspx.cs" AutoEventWireup="false" Inherits=" MCSDWebAppsVB.Transfer2" %>
 
 
private void butExecute_Click(object sender, System.EventArgs e)
{
   System.IO.StringWriter swrTarget = new System.IO.StringWriter();
   // Execute a Web form, store the results
   Server.Execute("Table.aspx", swrTarget);
   // Display the result in a literal control
   litTarget.Text = "<h2>Table Results</h2>" + swrTaget.ToString();
}
 
The "Execute" method's second argument is optional. If you omit it, the result is written to the current page. The
result is additive - the content of both pages is displayed at the same time and server controls on both pages can
pages can respond to user events.
 
When you combine Web forms using the "Execute" method, be aware that any postback events occurring on the second Web form
will clear the first Web form. For this reason, combining Web forms is mainly useful when the second Web form does not
contain controls that trigger postback events.