Solved

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

Posted on 2014-09-15
7
188 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now