Link to home
Start Free TrialLog in
Avatar of kevlause
kevlause

asked on

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
Avatar of YZlat
YZlat
Flag of United States of America image

use OK/Cancel message Box
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
Hi,

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

Regards,

Lee
Dim n As Integer = MsgBox("Yes or No?", MsgBoxStyle.OKCancel, "User Prompt")
are you using WebForms or WinForms?
Avatar of kevlause
kevlause

ASKER

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?
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;">
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?
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<body MS_POSITIONING="GridLayout" onload="userprompt('do you want to go to another page?');">
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.