Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Use confirm message to verfiy user action in asp.net vb web application

Posted on 2010-08-25
15
Medium Priority
?
542 Views
Last Modified: 2012-05-10
I have a web application that allows a user to upload a file.  Before uploading the file, I would like to prompt the user to click "OK" or "Cancel" on a popup confirmation screen.  In the confirmation screen, I would like to use some dynamic data stored in a session variable "Site".  In summary, the user clicks the button "Upload", then a confirmation box pops up and say "Do you want to upload a file for XYZ Company" < the session variable, user clicks "OK" or "Cancel" and upload routine is executed or canceled. Thaniks for the help.
0
Comment
Question by:OB1Canobie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
15 Comments
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 400 total points
ID: 33523448
Something like this perhaps:

<script type="text/javascript">
<!--
function prompter() {
var reply = prompt("Do you want to upload a file for " + <% =Session('companyName') %> + " Company", "")
}
//-->
</script>
0
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 1600 total points
ID: 33523551
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function confirmUpload() {
            return confirm("Do you want to upload this file for <%= Session("CompanyName") %>?");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClientClick="return confirmUpload()" />
   
    </div>
    </form>
</body>
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 33523728
Yes, Confirm, not Prompt. My mistake.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:OB1Canobie
ID: 33523772
How do I capture the response?  "OK" "Cancel" to execute or not execute the upload command?
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33523779
OnClientClick="return confirmUpload()"

That part will do it for you.  It will cancel the page submission if the user presses Cancel.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33523784
the "return" part is the key.
0
 

Author Comment

by:OB1Canobie
ID: 33524771
Guys, for some reason I am getting an error when using the session variable in the confirm box.  The error says that it is expecting expression.  Both the < > are underlined with the error.  What is wrong?

    <script type="text/javascript">
        <!--
        function ConfirmUpload() {
        return confirm("Do you want to upload a file for " + <%=Session("Facility")%> + "?", "")
        }
        //-->
    </script>
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33524979
Don't separate the text in the javascript:

return confirm("Do you want to upload a file for <%=Session("Facility")%>?", "")

I know it looks like it won't work, but it will.  Even though the <% tags are inside js quotes, the server will process them before the page sees any of the js.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33524993
Basically the Session variable gets written out before the browser loads the page, so by the time it gets there, if you have the text as you did:

return confirm("Do you want to upload a file for " + <%=Session("Facility")%> + "?", "")

then the browser will end up with:


return confirm("Do you want to upload a file for " + Company XYZ + "?", "")

(no quotes, causing the error).
0
 

Author Comment

by:OB1Canobie
ID: 33525364
One more question...What if I wanted to pass the Session Variable "Facility" in the button command.

<asp:Button CssClass="PostbackButton" ID="PostbackButton1" runat="server"
Text="Confirm postback with radconfirm" OnClientClick="return blockConfirm('Are you sure you want to upload a file to Site:<%=Session("Facility")%>?', event, 330, 100,'','Custom title');" />

I am calling a function but passing the variables for the confirm box in the java call.  I have everything working except for the Session Variable part. I can omit the session variable and the script works great. I tried your logic above but it does not like it.  Is it a combination of ' & ""??
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33525390
Yeah, it can be done, but it's a MISERABLE combination of single quotes and double quotes and escapes to do it.
I've generally just put it in separate functions specifically for that reason, major PITA to get it right.
0
 

Author Comment

by:OB1Canobie
ID: 33525398
can you do? I've tried every combination I can think of.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33525432
Actually, sorry, I think I might have lied to you.
If you're using a server control (asp:Button) as I'm assuming you are, then you can't do it that way.
You can't embed server tags <%%> inside parameters of a server control.

I think you might have to put in a separate function.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33525438
If you use an html control, THEN you can do it with the miserable combination i mentioned, but then you lose all the benefit of the server button.  Like the handler.
0
 

Author Comment

by:OB1Canobie
ID: 33525597
Snarf0001, you got me to thinking...Ok how can I do this. I guess I have been looking at this way too long.  I can do it from the code behind.. see the code that I initialize as soon as soon as the button is pressed:

PostbackButton1.Attributes("onclick") = "return blockConfirm('Are you sure you want to upload a file to Site:" & Session("Facility") & "?', event, 330, 100,'','Custom title');"

Worked great. Thanks for the help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question