Close a window then cause some server code to run if user hits can

G

Guest

I have this scenario (simplified)

function addnewdata () {
check for partial match already in db for information entered by user
if (partialmatch succeeds) {
open new window aspx page (using javascript) with a datagrid of these
partial match records (by doing a sqlcommand using some query string values
taken from opener data entered)
***
}
else
{
no partial matches already so do an insert of new data entered
}
}

at the point I have put *** - this is a new little window - it shows some
records. The user may hit SELECT for a given record. If they do, I have some
code which runs, inserts into the db, refreshes the opener screen and the
page is refreshed with this record which works fine. If they hit CANCEL they
have decided that they do not want to use a partial record and want to
proceed with the data entered. My question: If they hit cancel, how do I
then get into the ELSE clause of this function ??? Currently my cancel just
has javascript self.close in it. The window dissapears and the original data
entered is sitting there in the opener page, but i cannot figure out how to
say, ok now go and insert this data ! Do I have to use return false;
somewhere? not sure where. I thought about creating a new function to insert
a data if the user has hit cancel but dont know how to test that the user has
hit cancel in this window then run some server code. Real head block :eek:( any
help appreciated. many thanks. Lou.
 
K

Karl Seguin

Louise,

I see two options.
(a) when they hit cancel in the popup why not have the popup postback and
process the insert in the cancel's event, then close the popup
(b) have the cancel button a pure javascript which does self.close() but
before doing so makes the parent page postback and have it process the new
record.

I prefer the first approach because it's pretty simple server-side postback
(click button, in event do processing and then output self.close()). The
second approach forces you to use javascript to cause postback to occur,
which is doable..but not as clean.

Karl
 
G

Guest

Thank you. I cannot do A (dont think) because the Insert statement server
code resides on the opener page as does all the text boxes/drop downs with
all the user's entry in it, ready to be posted (because they've hit cancel on
the 'do you want to choose one of these instead' window).

The only thing i could do which is similar to your solution A would be to
pretend I am on the opener page and grab all of the user entry from all the
controls (using opener.getElementbyID("blah") 20 times and Insert here while
still in the little window, then close that window and reload the opener.
nasty though.

i have tried doing postback on the close of the little window, but i end up
in a loop of it finding partial matches! I somehow need to escape the fact
this, so act as if there were no partial matches in the first place. Since I
posted I put the insert statement into a function. called InsertData(). Can i
somehow call opener.InsertData() . This is exactly what I need to do, but i
cannot because opener is a javascript object (to mean parent page) and
InsertData() is a server function. so near but so far !
 
G

Guest

Karl. I think I have fixed it. In my Page_Load of the opener i have put an
else in the if (!ispostback) {
blah
}
else {
//we are in postback
if (hiddenflagtextbox.value ==1) {
InsertData();
}
}

On the CANCEL of the little box, I have set the field hiddenflagtextbox on
the opener page to 1, then called opener.document.forms[0].submit() then
window.close(). So because i've said do a submit on the opener it runs the
ELSE clause above, inserts the data the user entered originally and reloads.
I cannot believe it worked, it was a complete guess !
 
K

Karl Seguin

Louise,
Yes, having the popup set a value which you can read from Request.Form or
how you are doing it is the best way to separate between the two postbacks.

Glad i was able to help a bit.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


louise raisbeck said:
Karl. I think I have fixed it. In my Page_Load of the opener i have put an
else in the if (!ispostback) {
blah
}
else {
//we are in postback
if (hiddenflagtextbox.value ==1) {
InsertData();
}
}

On the CANCEL of the little box, I have set the field hiddenflagtextbox on
the opener page to 1, then called opener.document.forms[0].submit() then
window.close(). So because i've said do a submit on the opener it runs the
ELSE clause above, inserts the data the user entered originally and reloads.
I cannot believe it worked, it was a complete guess !

louise raisbeck said:
Thank you. I cannot do A (dont think) because the Insert statement server
code resides on the opener page as does all the text boxes/drop downs with
all the user's entry in it, ready to be posted (because they've hit cancel on
the 'do you want to choose one of these instead' window).

The only thing i could do which is similar to your solution A would be to
pretend I am on the opener page and grab all of the user entry from all the
controls (using opener.getElementbyID("blah") 20 times and Insert here while
still in the little window, then close that window and reload the opener.
nasty though.

i have tried doing postback on the close of the little window, but i end up
in a loop of it finding partial matches! I somehow need to escape the fact
this, so act as if there were no partial matches in the first place. Since I
posted I put the insert statement into a function. called InsertData(). Can i
somehow call opener.InsertData() . This is exactly what I need to do, but i
cannot because opener is a javascript object (to mean parent page) and
InsertData() is a server function. so near but so far !
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top