I’m trying to do something like
Server.Execute("page1.aspx");
but I need to pass POST data to this page.
Does anyone know how I can achieve this? Since Server.Execute only takes in 3 params, and none of these are anything to do with POST data.
Solution: 7 Hours Later…
Unfortunately, the only way I was able to do this was to pass the parameters in the query string (using a GET request). I’ve searched the web for a while now, and finally felt this was good enough for my application. I tested, and somehow the GET URL size limit of 4K chars does not hold good in this context.
I was able to successfully execute a Server.Execute method with 640K+ chars to another page, and it worked beautifully.
Server.Execute("~/pageB.aspx?foo=" + new string('x', 640000));
In pageB: Page_Load();
Response.Write(Request["foo"].ToString().Length());
Result: 640000
So I guess this will have to do for now.
I was afraid of having to send large parameters in the query string, but since it works, who am I to complain! 🙂
Is using
Server.Execute()absolutely necessary?If not, to get page A to post to page B, you could set page A’s
.PostBackURLto page B, then in page B check if(this.PreviousPage != null); if it’s not null, then in page B you can use something likethis.PreviousPage.FindControl()or((PageA)this.PreviousPage).txtFirstName.Textto get at the input values.If some values aren’t directly user-input, you could still assign the values to hidden controls, and make those hidden controls public properties of page A so that page B can access them after casting
.PreviousPagetoPageA.If you don’t want to require type-safe references to a specific sending class or interface, the simplest alternative would probably be to use something like this technique to encapsulate values in Context.Items: