ASP.NET confirmation box function code behind

I'm looking to pop up a message box on page load letting the user know there is some information they need (from a database) and if they want to view it or not.  I'm not good at javascript but I found the below code to create a pop up message. I need to make this a yes or no box and pass the response back into a variable. Can anyone help?

Public Sub ASPNET_MsgBox(ByVal Message As String)
        System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
        System.Web.HttpContext.Current.Response.Write("alert(""" & Message & """)" & vbCrLf)
        System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
    End Sub
kevlauseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YZlatCommented:
use OK/Cancel message Box
Lee SavidgeCommented:
Hi,

Instead of an alert() box, use a confirm() box. This will give you a Yes/No box on the screen. For example, something like:

Replace

System.Web.HttpContext.Current.Response.Write("alert(""" & Message & """)" & vbCrLf)

with

System.Web.HttpContext.Current.Response.Write("javascript:if(!(confirm('" & Message & "'))){window.event.returnValue=false;return false;}")

Regards,

Lee
Lee SavidgeCommented:
Hi,

Sorry, this will give you an Ok/Cancel box on the screen but it is the same thing :)

Regards,

Lee
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

YZlatCommented:
Dim n As Integer = MsgBox("Yes or No?", MsgBoxStyle.OKCancel, "User Prompt")
YZlatCommented:
are you using WebForms or WinForms?
YZlatCommented:
kevlauseAuthor Commented:
System.Web.HttpContext.Current.Response.Write("javascript:if(!(confirm('" & Message & "'))){window.event.returnValue=false;return false;}")

Will this give me a variable I can save?
YZlatCommented:
or use javascript:

add this javascript to <head> section of your html
<script language="javascript">
            <!--
                  function userprompt(question){
                  if (confirm(question)) {
                  return true;
                  }
                  else{return false;}
                  }

            //-->
            </script>

then change your opening <body> tag to this:

<body MS_POSITIONING="GridLayout" onload="userprompt('Continue?');return false;">
kevlauseAuthor Commented:
Maybe I need to reask my question:

Is there a way on page load in ASP.net 2.0 to promt a user if they would like to view another webpage then if the say no keep running the script on the page load?
YZlatCommented:
<script language="javascript">
          <!--
               function userprompt(question){
               if (confirm(question)) {
               window.location = 'page2'
               }
             
          //-->
          </script>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YZlatCommented:
<body MS_POSITIONING="GridLayout" onload="userprompt('do you want to go to another page?');">
kevlauseAuthor Commented:
Can I call that script from an if statement in my code behind? On page load I pull some data from my database, depending on what the data says I want to give the user an option to view a report or not. Can I call a java script function this way? I've only been able to do it on the aspx page.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.