I am trying to post from one website to another website on a different server. Both the posting page and the target page are Asp.Net 2.0 pages coded using C#. I want to Post rather than Get because I want to pass a variable value and not display it in a URL querystring. So I am trying to do that with (1) the variable's value in a hidden field and (2) a button with its PostBackUrl property set to the target site and page.
I set the PostBackUrl value in the Page_Init event handler.
btnContinue.PostBackUrl = strSite2Url;
The hidden field is loaded with the variable value in the Page_Load event handler.
When btnContinue is clicked with the mouse, this works fine. However, there are also cases when I need to do that same Post (with variable) before any user input (i.e. go immediately to the 2nd site-page). I tried to do this by firing the button's Click event with the following line:
btnContinue_Click((object)btnContinue, e);
in the Page_Load. It executed the btnContinue_Click event handler (which actually has no code in it) but not the PostBack. The calling site-page was rendered, not the PostBackUrl page. Then I moved that line to the Page_PreRender event handler, and got the same result. Then I moved that line into another button's Click event just to make sure the problem was not that the button and its PostBackUrl property had yet to load. When I clicked on that other button, I still got the same result - no PostBack.
Any insights on what I can do to fix this?