Solved

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

Posted on 2014-09-15
7
198 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
  • 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 80

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 80

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

679 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