Display MessageBox in ASP - asp-classic

I am new to code and starting with ASP. How do I create a simple message box so I can alert the users on the web page?

<% response.write("<script language=""javascript"">alert('Hello!');</script>") %>

Here is one way of doing it:
<%
Dim message
message = "This is my message"
Response.Write("<script language=VBScript>MsgBox """ + message + """</script>")
%>

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
alert("Hello!");
}
</script>
</body>
</html>
Copy Paste this in an HTML file and run in any browser , this should show an alert using javascript.

If you want to do it from code behind, try this:
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Message');", true);

Related

cardIdentifier returned in URL QueryString rather than hidden-field

I have integrated SagePay's 'Drop In Checkout' into a test solution. The issue is, when I am submitting the form for the 'cardIdentifier', it is returned in the URL as a QueryString, rather than a hidden field, as per the documentation.
http://integrations.sagepay.co.uk/content/getting-started-integrate-using-drop-checkout
"Once the customer initiates the form submission, the payment details are validated, tokenised and passed as a hidden field called cardIdentifier which is then posted with the rest of the form contents"
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CustomPayment.aspx.cs" Async="true" Inherits="SagePayDropInTest.CustomPayment" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://pi-test.sagepay.com/api/v1/js/sagepay-dropin.js"></script>
</head>
<body>
<div id="main">
<h1>My Test Shop</h1>
<form id ="checkout-form">
<h2>Payment Details</h2>
<div id="payment-details"></div>
<div id="submit-container">
<input type="submit"/>
</div>
</form>
</div>
<script>
sagepayCheckout({
merchantSessionKey: '<%=MerchID%>',
containerSelector: '#payment-details'
}).form({
formSelector: '#checkout-form'
});
</script>
</body>
</html>
C# CodeBehind
namespace SagePayDropInTest
{
public partial class CustomPayment : System.Web.UI.Page
{
public string MerchID = "";
protected void Page_Load(object sender, EventArgs e)
{
MerchID = GetMerchSessionID();
}}}
It does return the cardIdentifier, but just as a QueryString, but I would rather I was getting it as a hidden-field, as documented. The rest of the integration works as documented, it is just this step which is throwing me.
I am no doubt missing something obvious, and any guidance would be much appreciated.
Try changing the <form> tag to include a method="post" attribute. This should mean that the cardIdentifier is sent as a posted field rather than in the query string. The default method for a form is normally a GET request, the SagePay JS probably doesn't change this.
Also, there looks like an extra space in the <form id ="checkout-form"> tag as it is. I would recommend taking this out as some less forgiving browsers may not parse this correctly, breaking the CSS selector in your JS.

How to Launch a new page from href

I currently use button and trying to launch a new window passing parameter from mypage to the new page like this
<input type="button" name="launchpg" id="launchpg" value="LaunchPage" onclick="launch_page('<%=list_process_url%>',this.form.myform.options[this.form.myform.options.selectedIndex].value);"/>
Javascript is as below:
<script type="text/javascript">
//call servlet
function launch_new_window(list_process_url,smart_id)
{
popupWindow = window.open(list_process_url+"&id="+id,'List Process Page',
'scrollbars = yes');
}
I am trying to replace button with href link as in..
document.location='main.jsp?PAGE=myPage.jsp&id='+this.form.myform.options[this.form.myfom.options.selectedIndex].value;
I would like to use the same javascript for launching a new window passing the parameter to the script function.
The code however doesn't seem to work as it says Form is not valid for href.
Add this to wherever you want to launch a new page from:
window.location.href = "pageName.html";
<head>
<title></title>
<script src="Scripts/jquery-2.1.1.min.js"></script>
</head>
<body>
<div id="main">
<script>
$(function () {
<!--Some Logic-->
<!--window.location.href = "NewWindowName.html";-->
}
$("#btnSave").click(function () {
openNewWindow();
});
function openNewWindow()
{
window.location.href = "NewWindowName.html";
}
});
</script>
<article>
<button id="btnSave">Save Data</button>
</article>
</div>
</body>
I found a solution to my question:
Open New Window

Share session variables between asp.net and vb6

Hi i have a question about Session variables, i want to call in GET via ajax, from my .aspx page, a page .asp that have VB6 code inside, i need to share Session variables between them actually i tried this:
ASPX file
<html>
<head>
<title>let's try Ajax</title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
var request = $.ajax({
url: "/Default.asp",
type: "GET",
dataType: "html",
cache: "false"
});
request.done(function(msg){
$("#insert").html(msg);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
in the aspx: <%Response.Write(Session["try"].ToString()); %>
</div>
<div id="insert">
</div>
</form>
</body>
</html>
code behind page:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["try"] = "hello world";
}
}
finally .asp page
<%
[...]
Response.Write "" & Session("try")
Response.End
[...]
%>
Actually the Session doesn't show anything in the .asp page, but in the .aspx page shows it's string inside, what's wrong with my code? Is it possible to pass share a session?
I think, you want to share your session between Class ASP and ASP.Net. so you need to store
your session information in SQL server. Please refer below link
http://msdn.microsoft.com/en-us/library/aa479313.aspx

how can i get Response of OK button message box in client page

I wrote this line of code in my project..
ClientScript.RegisterStartupScript(this.GetType(), "My alert", "alert('" + mystringvariable + "');", true);
Response.Redirect("Home.aspx");
and what happened in it that it directly jump out to Home page without popping a message..
how can it pop up a message after pressing Ok button then it should redirect on Home page...
Pls Help me ASAP.
if you look at the generated HTML you will see that you say the browser to redirect before it will begin to execute the javascript. You have to do the redirect from JS too - here is a nice tutorial
Also take a look at
Alert and
Events
You should rather use JS confirm, and on ok button make JS redirect like:
<html>
<head>
<script type="text/javascript">
function confirmation() {
var answer = confirm("Question?")
if (answer){
//your home.aspx
window.location = "http://www.google.com/";
}
}
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="OK">
</form>
</body>
</html>
Where should go into ClientScript.RegisterStartupScript.

Disable/deny going back to previous page on asp.net 2.0

On my current project I want to deny going back once my customers hit submit button and redirected to the final page. How can I deny from going back to previous page or some mechanism to expire the page if the back button is clicked. I tried this code and it didn't work
page.response.cache.setcacheability(httpcacheability.nocache)
<script type="text/javascript">
history.forward();
</script>
</head>
<body>
<form runat="server" id="form1">
<%
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
Response.CacheControl = "no-cache"
%>
I put this in my master page and it works great!! :-)
Place the following between the <head> </head> of ALL your pages:
<script type="text/javascript">
history.forward();
</script>
And check this article out:
https://web.archive.org/web/20210927201700/http://www.4guysfromrolla.com/webtech/111500-1.shtml
I also had the same problem, use this Java script function, its 100% working fine, would not let you go back.
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>

Resources