pop up confirmation help me please

G

graphicsxp

Hi,
I have a function in my code-behind (vb.net) that checks if the file
the user is trying to upload already exists on the server. At that
point I'd like to display a pop up saying 'Are you sure you want to
overwrite the existing file?'. If the user clilcks yes, the function
carries on.

How can I do that? How can I display a javascript popup at that point
of the execution and get the value returned by that popup ?

I'm really struggling on this :(

Thank you
 
H

Hans Kesting

Hi,
I have a function in my code-behind (vb.net) that checks if the file
the user is trying to upload already exists on the server. At that
point I'd like to display a pop up saying 'Are you sure you want to
overwrite the existing file?'. If the user clilcks yes, the function
carries on.

How can I do that? How can I display a javascript popup at that point
of the execution and get the value returned by that popup ?

I'm really struggling on this :(

Thank you

You can't (as you found out) just show a popup in the middle of
server-side code.

You will need to remember the file server side, redirect to a "are you
sure" page and either remove the stored copy or overwrite the existing
file based on the reaction there (you might also consider giving a new
name).

Server side copy: either a temporary file (but: you will want to
provide some mechanism to delete old copies - as when you never
received an answer to the "are you sure" page), or a Byte[] in Session
(but: this might be big!)

Hans Kesting
 
J

John Timney \( MVP \)

Write the file to a temporary file on your server, then send back your
response asking them if they wish to overwrite. If they do just delete the
old and move the new.
 
M

Mark Rae

Sorry - ignore my earlier reply - didn't read your OP properly.

Go with Hans' suggestion...
 
G

graphicsxp

But yet I was told it is possible to do it in javascript using hidden
fields and stuff like that... have you heard of this ?
 
M

Mark Rae

But yet I was told it is possible to do it in javascript using hidden
fields and stuff like that... have you heard of this ?

Think about it:

JavaScript runs client-side i.e. on the user's machine.

How can it possibly know whether a file exists on the remote (web)server or
not...?
 
G

graphicsxp

no i was not talking about that. you obviously detect that in the code
behind. But then there should be a way to do a postback and display a
javascript confirmbox, get the answer, and do appropriate action
(upload or not the file)
 
M

Mark Rae

no i was not talking about that. you obviously detect that in the code
behind. But then there should be a way to do a postback and display a
javascript confirmbox, get the answer, and do appropriate action
(upload or not the file)

Of course, and that's what's been suggested - you just can't do it all in
one single postback... :)
 
J

Jose Rodriguez

not to muddy the waters...but wouldn't Ajax work for this scenario? , but of
course that has its own issues

Jose
 
Joined
May 13, 2009
Messages
1
Reaction score
0
I noticed this post while browsing. Yes I real I am about 3 years late, but what I think graphicsxp was looking for is something like this:


Dim strMessage As String = "Are you sure you want to overwrite the file?"

'finishes server processing, returns to client.
Dim strScript As String = "<script language=JavaScript>"
strScript += "confirm(""" & strMessage & """);"
strScript += "</script>"

Page.ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", strScript)
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top