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.Cur rent.Respo nse.Write( "<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
System.Web.HttpContext.Cur rent.Respo nse.Write( "alert(""" & Message & """)" & vbCrLf)
System.Web.HttpContext.Cur rent.Respo nse.Write( "</SCRIPT> ")
End Sub
Public Sub ASPNET_MsgBox(ByVal Message As String)
System.Web.HttpContext.Cur
System.Web.HttpContext.Cur
System.Web.HttpContext.Cur
End Sub
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.Cur rent.Respo nse.Write( "alert(""" & Message & """)" & vbCrLf)
with
System.Web.HttpContext.Cur rent.Respo nse.Write( "javascrip t:if(!(con firm('" & Message & "'))){window.event.returnV alue=false ;return false;}")
Regards,
Lee
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.Cur
with
System.Web.HttpContext.Cur
Regards,
Lee
Hi,
Sorry, this will give you an Ok/Cancel box on the screen but it is the same thing :)
Regards,
Lee
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?
if webforms, you cannot use MsgBox
check this out:
http://www.opinionatedgeek.com/DotNet/Products/PowerPack/Examples/PopupImageButton.aspx
check this out:
http://www.opinionatedgeek.com/DotNet/Products/PowerPack/Examples/PopupImageButton.aspx
ASKER
System.Web.HttpContext.Cur rent.Respo nse.Write( "javascrip t:if(!(con firm('" & Message & "'))){window.event.returnV alue=false ;return false;}")
Will this give me a variable I can save?
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('Contin ue?');retu rn false;">
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
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<body MS_POSITIONING="GridLayout " onload="userprompt('do you want to go to another page?');">
ASKER
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.