tags:

views:

393

answers:

2

Hi

I need to pass 4 arguments (3 strings and one comma separated list) from an ASP.NET page to another ASP.NET page using jQuery. The destination page ought to be launched as a separate window, which works fine with the following jQuery snippet:

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

How can I pass the arguments to the destination page? I am trying to avoid the query string to pass the arguments because:

  1. I don't want to show the url arguments (which can also be very long) in the destination window.

  2. There are some special characters like ',/,\, & etc. in the string arguments.

Please suggest.

Edit: I'm trying to access the arguments in the script section of the aspx file i.e.

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

My specific need for the arguments in the Page_Load of the script section stems from the fact that I am creating a few dynamic Chart controls in the Page_Load which depend on these arguments.

cheers

+4  A: 
John K
Thanks. I need to launch the destination page from jQuery button click handler as I'm collecting the ids and text values of few HTML elements in the jQuery button click. Secondly, I need to launch a new page, instead of a redirect. window.open() does that for me but I don't think it supports a POST like behavior.
Andriyev
I edited to include a link to jQuery POST examples. Am I heading in the right direction?
John K
Thanks again. Much of your reply makes sense to me. And $.POST() does take the control to the destination page. But the control comes back to the source page. Also, the destination page doesn't get launched as a separate page.
Andriyev
I'm still hacking at it. Code sample is in progress..., however what's interesting right now is by using the jQuery syntax `$(element, context)` in the MAIN window and by providing the popup's window handle as the context jQuery is accessing the DOM of the popup window and displaying stuff only seen in the popup. Hopefully .get and .post can be used to affect the popup too... time will tell.
John K
Solution completed. It opens a poupup window and posts data from your main page to it - the solution uses jQuery/AJAX as you requested. If you just copy and paste the source code into three files, you can run it yourself.
John K
Thanks for your patience and efforts. Almost everything works great. Just that I'm unable to access the arguments in the page load of my ASP.NET destination page. How do I do that? Do I need to modify the page load argument list to receive these arguments?
Andriyev
I replaced data.html with an ASP.NET dynamic page named `process.aspx` containing server processing of the passed data. Throw all this into an ASP.NET web application to run it.
John K
Thanks again. I tried accessing the argument using Request["name"], but it always gives me (no name). One thing which I forgot to mention is added as an Edit in the question, i.e. I need to access the arguments in the C# script section of the aspx file.
Andriyev
@Andriyev: That's odd app behaviour. What you might do is boil it down to a simple scenario around the new problem (of ajax arguments not being seen by ASP.NET), then post a separate question to SO (put in details of browser, version, etc.) You will get more specific answers this way and likely solve it sooner.
John K
A: 

If you keep a reference to the new window when you open it, ie var destWin = window.open(...) then you can access the variables and methods on the destWin window object. Alternatively you can "reach back" from the destination window with window.opener.

AUSteve