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

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

P: n/a
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 :o( any
help appreciated. many thanks. Lou.
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E2**********************************@microsof t.com...
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 :o( any help appreciated. many thanks. Lou.

Nov 19 '05 #2

P: n/a
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 !

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E2**********************************@microsof t.com...
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 :o(

any
help appreciated. many thanks. Lou.


Nov 19 '05 #3

P: n/a
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" wrote:
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 !

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E2**********************************@microsof t.com...
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 :o(

any
help appreciated. many thanks. Lou.


Nov 19 '05 #4

P: n/a
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" <lo************@discussions.microsoft.com> wrote in
message news:9F**********************************@microsof t.com...
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" wrote:
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 !

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E2**********************************@microsof t.com...
> 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 :o( any
> help appreciated. many thanks. Lou.

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.