471,887 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Any thoughts on transferring data between pages?

I am looking for some guidance on transferring data between two pages in my
ASP.net Web app (intranet).
I have a form that will have a button and a text box on it (among other
controls of course)
When I click the button, I want to open a contacts page which is already
built and functional. From there I want the user to select a contact (using
the search and browse tools on that page)
When the user selects one of the contacts, I want the information I store to
a string to appear in the text box on the original form. Closing the form may
happen but I can take care of that.
Now the big question is how do I send this information to the original page?
I can use cookies, and I can use session variables, but how will I tell the
text box to update its info?
The only way that I can think of accomplishing this is by designing my own
class (in a module, so it is page independent) and have an event that fires
when the data comes in. This still is a bit fuzzy to me and is going to take
me a while to figure out, as I still have to deal with view states, and see
what is going to happen.
Is there some way of doing this that I am missing?
Jul 21 '05 #1
1 1518
I like to use javascript to send the desired value back to the parent window.
Here is the code I use. Just put this code in a picker.js file and include
it in
both the parent and spawned pages.

//This finds the id of the form the named field is on
//It could be avoided if you alter the input parameters for
function findParentFormIndex(strElementName) {
for (x = 0; x < document.forms.length; x++)
for (y = 0; y < document.forms[x].length; y++)
if (document.forms[x].elements[y].name == strElementName)
return x;

//this opens the "picker" window passing the full current field and value
//I call this from a button or link on the parent page.
function launchPicker(fieldName, fieldValue) {
var parentFormIndex;
parentFormIndex = findParentFormIndex(fieldName);
var thisField = eval('document.'+ document.forms[parentFormIndex].name
+'.'+ fieldName);
if (thisField.onchange == null) { thisField.onchange = fieldChange; }
if (fieldValue == null) { fieldValue = thisField.value; }
//change the url to suite your fancy.
winEmail = window.open(
'/includes/picker_category.asp?' +
'page_action=single_select' +
'&fieldName='+ document.forms[parentFormIndex].name +'.'+ fieldName +
'&fieldValue='+ fieldValue,

//this defines the onChange event for fields where it is not defined
function fieldChange() {}

//this returns the value to the desired field
//call this from the spawned page using
//the variables as received from the querystring
//changeing fieldValue if appropriate.
function openerSetVal(fieldName, fieldValue) {
eval('window.opener.'+ fieldName +'.value = "'+ fieldValue +'"');
try {
eval('window.opener.'+ fieldName +'.onchange()');
} catch(err) {
//some textboxes don't like the onchange event

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by hzomorodi | last post: by
2 posts views Thread by Rani | last post: by
15 posts views Thread by http://www.visual-basic-data-mining.net/forum | last post: by
1 post views Thread by Asaf | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.