By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Any thoughts on transferring data between pages?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
Jed
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
//launchPicker
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,
'winPicker',
'top=50,left=50,scrollbars=yes'
);
}

//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 +'"');
self.close();
try {
eval('window.opener.'+ fieldName +'.onchange()');
} catch(err) {
//some textboxes don't like the onchange event
return;
}
}

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.