Passing arguments from one asp.net page to another using jQuery

I need to pass 4 arguments (3 lines and one list with commas) from an ASP.NET page to another ASP.NET page using jQuery. The landing page should be run as a separate window that works great with the following jQuery snippet:

$('#sourcePageBtn').click(function(){
   window.open("destinationPage.aspx");
   return false;
});

How do I pass arguments to the landing page? I am trying to avoid the query string in order to pass arguments, because:

  • I do not want to show url arguments (which can also be very long) in the destination window.

  • There are some special characters in string arguments, such as', /, \, etc.

Please offer.

Edit: I am trying to access the arguments in the script section of an aspx ie file

<script language="C#" runat="server">
    protected void Page_Load ( object src, EventArgs e) 
    {
     //Creating dynamic asp controls here
    }
</script>

Page_Load script , Page_Load, .

+3
2

( )

  • POST GET. POST , URL- . ( URL- , , , ).

  • URL , .

, - . . .

HTTP- . . . . jQuery, ...

. jQuery , JavaScript . - , JavaScript . JavaScript/jQuery, , .

: ( ASP.NET)

:

. POST, . :

  • script ( )
  • main script
  • main script POST ( AJAX) ( )
  • main script .

.

, . 3 , Google Chrome 3.0.195.38. . jquery-1.3.2.js, .

main_page.html

, . , id=sourcePageBtn.

/, POST (,). / .

<html>

<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
</head>

<body>

<a id="sourcePageBtn" href="javascript:void(0);">click to launch popup window</a>

<script>

$(function() {
 $('#sourcePageBtn').click( function() {

  // Open popup window if not already open, and store its handle into jQuery data.
  ($(window).data('popup') && !$(window).data('popup').closed) 
   || $(window).data('popup', window.open('popup.html','MyPopupWin'));

  // Reference the popup window handle.
  var wndPop = $(window).data('popup');

  // Waits until popup is loaded and ready, then starts using it
  (waitAndPost = function() {
   // If popup not loaded, Wait for 200 more milliseconds before retrying
   if (!wndPop || !wndPop['ready']) 
    setTimeout(waitAndPost, 200);

   else  { 
       // Logic to post (pass args) and display result in popup window...
    // POST args name=John, time=2pm to the process.aspx page...
    $.post('process.aspx', { name: "John", time: "2pm" }, function(data) {
     // and display the response in the popup window <P> element.
     $('p',wndPop.document).html(data);
    });
   }
  })(); //First call to the waitAndPost() function.


 });
});

</script>
</body>
</html>

popup.html

, . popup.html jQuery script .

"", window['ready'] = true, DOM . script , .

<html>

<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
</head>

<body>
 <!--  The example P element to display HTTP response inside -->
 <p>page is loaded</p>
</body>

<script>
    $(function() {
     window['ready'] = true;
    });
</script>

</html>

process.aspx.cs( # ASP.NET process.aspx)

script. AJAX Page.Request. , .

public partial class process : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {
        // Access "name" argument.
        string strName = Request["name"] ?? "(no name)";
        // Access "time" argument. 
        string strTime = Request["time"] ?? "(no time)";

        Response.ContentType = "text/plain";
        Response.Write(string.Format("{0} arrives at {1}", strName, strTime));
    }

    protected override void Render(System.Web.UI.HtmlTextWriter writer) {
        // Just to suppress Page from outputting extraneous HTML tags.
        //base.Render(writer); //don't run.
    }

}

/ . , "[name] arrives at [time]"


: HTTP Made Really Easy, jQuery Ajax members .

+5

, var destWin = window.open(...), destWin. "" window.opener.

0

Source: https://habr.com/ru/post/1727570/


All Articles