g_johnson
asked on
Why doesn't this alert using java in ASPX work?
Hi.
I have this code in an ASPX page:
Dim b As Boolean = rept.ReportProduction()
If b = False Then
Page.ClientScript.Register StartupScr ipt(Page.G etType(), "Key1", "showDialogue('" & rept.errMess & ".')", True)
End If
<script type="text/javascript" language="javascript">
function showDialogue(message) { alert(message); }
</script>
The above does not work.
However, this does pop the alert:
Dim b As Boolean = rept.ReportProduction()
If b = False Then
Page.ClientScript.Register StartupScr ipt(Page.G etType(), "Key1", "showDialogue('" & "junk" & ".')", True)
End If
In short, if I use a variable it doesn't work; if I just put in text it does work.
Can it be made to work with a variable?
I have this code in an ASPX page:
Dim b As Boolean = rept.ReportProduction()
If b = False Then
Page.ClientScript.Register
End If
<script type="text/javascript" language="javascript">
function showDialogue(message) { alert(message); }
</script>
The above does not work.
However, this does pop the alert:
Dim b As Boolean = rept.ReportProduction()
If b = False Then
Page.ClientScript.Register
End If
In short, if I use a variable it doesn't work; if I just put in text it does work.
Can it be made to work with a variable?
Best guess rept.errMess is null
ASKER
Sorry -- I should have made that clear. rept.errMess is a rather long string:
Error in ReportProduction: 45: 80: Could not Report Production: Imitmidx.Read:Item Number/Location not found: FORK / MA
Error in ReportProduction: 45: 80: Could not Report Production: Imitmidx.Read:Item Number/Location not found: FORK / MA
Use regular c# when javascript doesn't work
Webform1.aspx.cs
with help from http://bit.ly/ZnblOK
Webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication18
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { }
public void ErrorTrap(string str) {
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, "alert('" + str + "');", true);
}
protected void Button1_Click1(object sender, EventArgs e)
{
ErrorTrap(TextBox1.Text);
TextBox1.Text = "";
}
}
}
WebForm1.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication18.WebForm1" %>
<!DOCTYPE html>
<html4f>
<head runat="server">
<title>Alert Box</title>
<style type="text/css">
.auto-style1 {
text-align: left;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="auto-style1">
<div class="auto-style1"><asp:TextBox ID="TextBox1" runat="server" Height="30px" Width="345px"></asp:TextBox></div>
<div class="auto-style1">
<br />
</div>
<div>
<p class="auto-style1"> <asp:Button ID="Button1" runat="server" Text="Click To Show Text in Alert" OnClick="Button1_Click1" style="margin-bottom: 0px" Width="354px"></asp:Button>/</div>
</form>
</body>
</html>
with help from http://bit.ly/ZnblOK
ASKER
That also is not working. If I just type in something like "junk" instead of my variable, it works, but if I use my variable it does not work. I'm working in VB, not C#, but I was able to translate your code to see the results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
perhaps your variable is not in scope
ASKER
This turns out to be the real issue. There was nothing wrong with the code itself.