I need to know how to trigger a postback from one aspx page to another

nsanoir 1 Reputation point
2021-01-13T15:52:52.177+00:00

I have a one.aspx page that is running and I need to trigger a postback on two.aspx. Can this be done? If so, how?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,304 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,362 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 112.9K Reputation points
    2021-01-13T19:18:47.643+00:00

    The simple and archaic method is probably this: define a <form> element, set method attribute to "post", set action attribute to the target two.aspx address, and maybe make it hidden using styles. Then insert a series of <input type= “hidden” name=“…” value =“…”/> elements, which will hold the parameters to be passed to two.aspx.

    In order to post the data, use submit() function of <form> element using JavaScript. For example:

    <form id="form1" method="post" action="two.aspx">
       <input type="hidden" name="param1" value="value1"/>
    </form>
    

    In JavaScript:

    document.getElementById("form1").submit(). 
    

    Probably this is another good place for such aspects: https://forums.asp.net/

    0 comments No comments

  2. SurferOnWww 1,996 Reputation points
    2021-01-14T01:17:17.43+00:00

    I have a one.aspx page that is running and I need to trigger a postback on two.aspx. Can this be done? If so, how?

    ASP.NET Web Forms has such function so called the cross-page post back. If you use the control such as the Button, LinkButton and ImageButton in one.aspx to move to two.aspx set the URL of two.aspx to the PostBackUrl property of the control.

    For detail, refer to the following Microsoft document:

    Cross-Page Posting in ASP.NET Web Pages

    0 comments No comments