Solved

Why doesn't this alert using java in ASPX work?

Posted on 2014-09-15
7
201 Views
Last Modified: 2014-09-20
Hi.

I have this code in an ASPX page:

        Dim b As Boolean = rept.ReportProduction()
       
        If b = False Then
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "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.RegisterStartupScript(Page.GetType(), "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?
0
Comment
Question by:g_johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40323278
Best guess rept.errMess is null
0
 
LVL 4

Author Comment

by:g_johnson
ID: 40323292
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
0
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 40323872
Use regular c# when javascript doesn't work


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 = "";
        }
    }
}

Open in new window

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">&nbsp;<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>

Open in new window


with help from http://bit.ly/ZnblOK
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 4

Author Comment

by:g_johnson
ID: 40324025
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.
0
 
LVL 4

Accepted Solution

by:
g_johnson earned 0 total points
ID: 40324072
This turns out to be unprintables in the string.  I wrote a routine to remove unprintables from the string and now it works fine.

Thanks for trying.
0
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 40324219
perhaps your variable is not in scope
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 40334196
This turns out to be the real issue.  There was nothing wrong with the code itself.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question