|
I had the opportunity to explain this in detail on an article at 4guysfromrolla, at: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx. Although that article was a year ago, I still get regular emails about parts of it. Most people wanted to know how to have a button give a Yes/No prompt, and then trigger the appropriate server event. Eventually to simplify it I wrote a custom-server control and uploaded it to the control gallery on www.asp.net, at: http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=2071&tabindex=2. It's a free control, with a link to a demo.
[Update]: I posted the source code for this control:
The gist of it is you:
Essentially, you go from Server to Client by registering the script, you go from client to server by submitting the form, and you make data accessible to both by storing it in a runat=server hidden control.
Tim:
Hey Edwin,
I assume that this condition is on the server? In this case the problem is
that the processing is on the server, but the messageBox is on the client.
This is not like a WinForm where a MsgBox just pops up and halts the
thread. What you would need to do is:
thanks for your article Adding Client-Side Message Boxes in your ASP.NET
Web
> Pages, Part 2 , very helpful, the only problem i had was receiving
error;
>
> BC30648: String constants must end with a double quote
> and needed to substitute the last line with strScript +=
"<"&"/script>" and
> it worked fine
> 'finishes server processing, returns to client.
> Dim strScript As String = " "
>
Hey Michael,
Glad you enjoyed the article. Where you able to get the download Demo to
work?
Conceptually what's going on is that we need to create JavaScript to
handle the messageBox, and we're concatenating strings to do that. "String
constants must end with a double quote" sounds like an error in the string
concatenation. However "</script>" is a valid string literal. Are you
getting this as a compile-time error? Did you change something from the
demo, or have I misunderstood the problem?
I have a question similar to Edwin's. I want to have the confirm box popup
based on a condition. However, it will occur on a click event. This is
what I'm trying to do. I have a file upload and when the user clicks the
upload button, i want to check if the file exists already, and then confirm
if they want to overwrite it. If yes, then upload, if not, then don't. I
don't know why I'm so stuck on this! Thanks in advance...
Hey Caitny. Good question. What you can do is:
1 - When the user selects the file and clicks the update button
2 - post (or callback) to the server, check if the entered file exists from
the filePicker
3 - If it does, then register a startup script with the onclick event.
This script will have a confirm()
4 - If the user clicks Yes, then do a Form.Submit() which takes you back to
the server.
5 - If the user clicks No, then do nothing (i.e. don't FOrm.Submit)