Need help with Page Interaction using ASP.Net 2.0

G

Guest

In my design, page 1 is a web-based dashboard used to assign resources to an
organization. The dashboard includes information about the organization as
well as a list of all assigned resources. Included on page 1 is a lookup
button that will open a search menu to find additional resources to assign to
the orgaization. When I press the lookup button on page 1, I want to leave
page 1 open and open a new search page. On the search page, I want to
perform a search and get a list of resources to choose from to assign to the
organization on the first page. When I select the resource, I want to
automatically update tje listed of assigned resources on page 1. The key
here is that I want to keep both pages open at the same time as part of my
workflow.

Cross-page postbacks don't seem to work because it closes the submitting
page. Any recommendations? Any examples?

Thank you!
 
F

Flinky Wisty Pomm

I use Javascript to get cross-page callbacks working. All this
server-side stuff gets on my wick.

On your pop-up page, in an init function called from body.onload you
can do something like

var CallHome;
function init()
{
this.CallHome = this.opener.getCallbackFunction(this);
}


and in your opening page


function getCallbackFunction(caller)
{
// add your own logic based on caller.name if you're
// going to have several control windows open
return updateResourceList;
}

function updateResourceList(resource)
{
// do what you have to do to update your list
// with the value(s) from resource
}

now, when the user selects a resource in your popup window you can call
CallHome() and pass the value that they've selected. The nice thing
about doing it this way is that neither page really cares about the
other, you can mix and match pages with callback functions as you
please. If your popup refreshes, or does a postback, it will
automagically dial home again to get the callback function.
 
G

Guest

Thank you for your recommendation. I'd like to try that approach but I'm
wondering if you have any fuller examples including the aspx source for both
the primary web page and the popup? I'm somewhat of a novice when it comes
to javascript.

Thx - Tim
 
F

Flinky Wisty Pomm

Sorry for the delay, I've been snowed under.

For ASPX, you'll have to work something out yourself - if you need to
post on the opener page, call the __doPostback__() function added by
ASP.Net. For extra slickness points, try using Ajax to do the refresh
for the opener. Look up Client Callbacks for ASP.Net 2.0 or look at one
of the open libraries like Ajax.Net which is much nicer.

Here's the source for a quick and dirty demo of the javascript
technique, you can tidy this up immensely. I use a hashtable of window
names on opener pages and look up the function from that, but this will
work for one page.

<code>
<!-- 1.htm is the parent file -->
<html>
<head>
<script type="text/javascript">
var myChild;
function getCallback(window)
{
// note: no brackets - we want to return the function, not call
it
return updateReceiverBox;
}

// here's the function that handles the child response.
function updateReceiverBox(text)
{
document.getElementById("receiverBox1").value = text;
alert("got text:" +text);
}

function openChild()
{
myChild = window.open("2.htm");
// you can close or refresh or generally jiggle about with your
child window with the reference returned from window.open.
}
</script>
</head>

<body>
<input type="text" id="receiverBox1" />
<input type="button" id="btnOpenWindow" onclick="openChild()"
text="open child window" />
</body>
</html>
</code>


<code>
<html>
<head>
<script type="text/javascript">
// sendValue gets the return value from the page and passes it to the
function CallHome
//which is assigned by the opener. If you need to pass multiple values,
build a javascript
//object instead like
// var myobject = new object()
// myObject.SomeField = someValue;
// myObject.SomeOtherField = someOtherValue;
// CallHome(myObject);

function sendValue()
{
var text = document.getElementById("senderBox1").value;
CallHome(text);
}

// handshake sets the value of CallHome. Make sure this is called from
body.onload
// doing it from the child window means that your child can do
postbacks or refreshes
// and it will re-handshake when it loads again.
function Handshake()
{
this.CallHome = this.opener.getCallback(this);
}
</script>
</head>
<body onload="Handshake()">

<input type="text" id="senderBox1" />
<input type="button" onclick="sendValue()" value="send value" />
</body>
</html>
</code>


Hope that's some use to you. It's nice little tricks like this that
make me love javascript. Closures and first-class functions without
that whole Delegate mess. Bliss.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top