How to pop up question from code-behind function ?

R

Radu

Hi.

User enters ProductID. When he clicks on the "ADD" button, I need to
a. search in my database
b. if no record is found for that ID, then allow code to add a new
record to my table
c. if a record is found, I should ask the user "a product with this ID
already exists, with this and that characteristics. Do you still want
to add a new record (Y/N) ?"

My problem is how to create such a modal dialogbox from code-behind,
read the user's answer, and depending on that, continue or not with my
function.

I cannot add a javascript "confirm" code to my "ADD" button because
first I need to search in the database and then maybe ask the user if
I should continue or not - if I had such a javascript code, then the
question would be asked first, before the server code having a chance
to run. However, I need to ask the question in the middle of my code-
behind "ADD" function.

Thank you very much
Alex.
 
G

Göran Andersson

Radu said:
Hi.

User enters ProductID. When he clicks on the "ADD" button, I need to
a. search in my database
b. if no record is found for that ID, then allow code to add a new
record to my table
c. if a record is found, I should ask the user "a product with this ID
already exists, with this and that characteristics. Do you still want
to add a new record (Y/N) ?"

My problem is how to create such a modal dialogbox from code-behind,
read the user's answer, and depending on that, continue or not with my
function.

I cannot add a javascript "confirm" code to my "ADD" button because
first I need to search in the database and then maybe ask the user if
I should continue or not - if I had such a javascript code, then the
question would be asked first, before the server code having a chance
to run. However, I need to ask the question in the middle of my code-
behind "ADD" function.

That is not possible. You can't interact with the user in any way while
the server code is running.

To show any kind of message to the user you have to add code for showing
the message to the page that is currently created, then complete the
server code and let the page go to the browser. That means that you need
to continue the process after the user has made the choise and the
browser has made another postback to the server.
 
R

Radu

Hmm - that's interesting. It happens on other browsers on XP too e.g.
FireFox, Safari, Opera, SeaMonkey etc...

I'll raise it with Microsoft...

Thanks to all !

1. I could not read the MSDN pages either, for the reason mentioned
above - I have tried on two computers, both with XP. However, in Vista
it's okay. Also, this is happening not only for this link, but for all
MSDN "magazine" pages.
2. The idea with the AJAX modal popup extender started me on a good
path. After a lot of searching, reading and many tries, my project
works fine (of course, it is much more complex than what I've
described in my post, but now I have only one postback when entering/
validating input data, which is acceptable). Now if I only I could
minimize the flashing of the screen (i.e. refresh only a part of my
grid).... I will investigate this.

Thank you very much for reading and answering ! I appreciate it.
Alex
 

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

Top