Skip to main content
April 24, 2006
Answered

Alert message in vb

  • April 24, 2006
  • 8 replies
  • 1127 views
Visual Basic Noob here. I'm trying to make an alert dialog pop up if the recordcount of a dataset is 0 meaning that it didn't find a match between an id and the currently logged in user. Below is the code I came up with but obviously it doesn't work. Is it possible to pop up an alert box from the if statement like I'm trying to do? If so, can someone help me with the syntax of my code. It is below:

<%
IF editmessage.RecordCount = 0 THEN
Alert("You do not have permission to edit this record.");
END IF
%>

Thanks!
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
You are trying to create a popup message that will only popup on the
webserver - nobody will see it.
As Lionstone has pretty much said, you basically have two options - one is
much more reliable than the other.

1. Redirect back to your edit page and pass a flag in the querystring. On
the edit page, you check for that flag and if it meets a specific condition,
you display some big red text on the page to let your user know the problem
that exists.

2. (A bodge that you really should avoid) You can test the flag in a
VBScript statement and have that test produce the javascript to popup an
alert window containing your message to the user.

What you cannot do is test the condition on the server and popup a message
to the user at the same time - the user is only at the client end of the
equasion and that test only occurs at the server end of the equasion...

I highly recommend using option 1 in this (and most other) case.
Cheers,
Rob
http://robgt.com/ [Tutorials and Extensions]
Firebox stuff: http://robgt.com/firebox
Skype stuff: http://robgt.com/skype
Dell stuff: http://robgt.com/dell
SatNav stuff: http://robgt.com/satnav




Thanks for everyone's help. I think I have a handle on the situation now. What I'm going to do is have it check if the record count is = 0 if it is I'm going to redirect them like Lionstone suggested.

8 replies

Inspiring
April 24, 2006

"schristy" <webforumsuser@macromedia.com> wrote in message
news:e2itjd$p80$1@forums.macromedia.com...
> <%
> IF editmessage.RecordCount = 0 THEN
> Alert("You do not have permission to edit this record.");
> END IF
> %>
>

You're mixing server-side VBScript with client side JavaScript. If the
record count is 0, set a flag. Later, use that flag to write a line of
JavaScript for the user (or better yet, print a message on the page so you
can at least be sure the message gets through).

If editmessage.RecordCount = 0 Then
ZeroFlag = True
Else
ZeroFlag = False
End If
....
<%If ZeroFlag Then%>
<p class="error">No records were affected by your update.</p>
<%End If%>


April 24, 2006
I already know that I could just redirect it to an error message page, but I'd rather have it pop up an alert message and then take the user directly back to the edit_delete page.

Like this:

<%
IF editmessage.RecordCount = 0 THEN
Alert("You do not have permission to edit this record.");
Response.Redirect (“edit_delete.aspx”)
END IF
%>

The missing piece of the puzzle is how to make the alert dialog pop up. Perhaps this isn't possible in VB?