Solved

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

Posted on 2014-09-15
7
185 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 78

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 78

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now