General discussion

Locked

How to pass data between asp.net(c#) and Javascript or the main web page

By colin ·
Hi all,

I've run into a bit of a mind bender. I have a web application I'm building using asp.net(c#).

The skinny is like most regular apps it opens windows to gather user input and to do things like save, open etc... The windows opened are of course web page popups that have the built in ability to pass data back to the original application page. They do this using javascript, because that's how I know how to do it. The only problem I have is when I retrieve information from the database in the windows(web page popups) I have to use asp.net(c#) to do it and I don't know how to pass this back to the main window. If I could just somehow pass it to the javascript I'd be good to go! Any thoughts? Maybe somehow passing it to a hidden form input? Textarea or <div>?

any help/thoughts is much appreciated as this is the last bit I need to do. =)

Cheers,

-Colin

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by adi_ady_ade In reply to How to pass data between ...

I'm not sure if this is the answer, but have a look at data piping with JavaScript.

http://tutorial129.easycfm.com/

http://www.depressedpress.com/DepressedPress/Content/ColdFusion/Essays/GIFAsPipe/Index.cfm

http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=data+piping+javascript+cookies

Might be the answer )

Ade

Collapse -

Pass data to/from the Server via XMLHTTP

by w.lievers In reply to How to pass data between ...

Colin, I use Javascript/VBscript to build an XML request that gets passed to the Server via XMLHTTP (there are numerous articles on the web regarding the gory details). HTH

w.Lievers

Collapse -

Passing data back to a page using JS...

by junk In reply to How to pass data between ...

Hey Colin, my name is Colin too! While you could use the XMLHTTP or the Javascript data piping, if you do want to solve your problem using just Javascript and ASP.Net, here is one potential solution.

If you used window.open() to launch your popup, then there is a property called opener that you can use to refer back to the main page. You could set the value of a hidden field using something like:

opener.document.forms[0].<name of hidden field>.value = <value>;

Also, if you're using .Net then sometimes you might want to force the main page to do a postback from a popup (I have needed to do this where I have had popups that insert things into the db that my main page needs to know about), you can do this from your popup using something like:

opener.eval("__doPostBack('_refresh','')");

The '_refresh' would be different based on the method you are calling.

Colin

Collapse -

Write Javascript

by RMcVay In reply to How to pass data between ...

First you should make sure you ONLY put data on the page that is really needed as data. Most often you can just use it as input element values, bypassing the javascript entirely. If it must be used by javascript and it can't be in form element values then you can just use your server-side code (ala Response.write()) to write javascript to the page to initialize javascript variables to the values needed. This is especially effective when initialized arrays are required.

Collapse -

A couple alternatives

by programmeroo In reply to Write Javascript

Hi Colin,
I have addressed this problem before by using JScript and Server code. You can open a window to another aspx page, then go back. This give the user the ability to enter the input on the second page and return to the first, using stored session variables.

<SCRIPT language="JScript">
window.open("secondPage.aspx","_blank");
window.history.back();
</SCRIPT>

In another case I needed to communicate with Script code on the same page, this can be done via the server variables __EVENTTARGET and __EVENTARGUMENT.

-Andy

Collapse -

use web forms

by ge.goodman In reply to How to pass data between ...

I use ASP.NET web forms as my popup windows, use a bit of client-side javascript to show them, and pass all data between them using session variables which you remove from the session as soon as you've read their values in Page_Load. Works a treat. Can send you an example if you want.

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums