Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup message 3

Status
Not open for further replies.

Rexxx

MIS
Oct 16, 2001
47
Within my aspx file I need to code it to display a popup message (as opposed to using an html page message) to inform the user whether a certain record was successfully entered into an SQL database. As of now my sql stored procedure to add a record returns a value -1 if the record is unsuccessful that I could use in an if statement. I have used similar code to display a certain popup message upon button clicks such as this message on a delete record button click:

btndelcompany.Attributes.Add("onClick","javascript: return confirm('Are You Sure You Want to Delete this Record?')")

So I'm fairly certain it can be done but not sure how to setup. Can you help?
 
Hi,
U can have a Flow Layout HTML Control (Div tag). And from the Code Behind After u add the record to the database. Subtitute the javascript function into the Div.InnerHTML.

Eg.,
Protected WithEvents DivScript as System.Web.UI.HtmlControls.HtmlGenericControl

Private Sub AddRecord()
'Write Code to Add to the Database
DivScript.InnerHTML = &quot;<Script language='javascript'> alert('record was successfully entered into an SQL database') </Script> &quot;

End Sub

Once this is Done. The Script in the Div Gets Executed in the Client Side and so the Alert it shown to the User. The Same way we can show the Error Message Also....

Hope This Helps.
 
I get the following error message:

Compiler Error Message: BC30451: Name 'DivScript' is not declared
 
You can also use a simple label to do the job. Set it's visibility to False and it's text attribute to your javascript. Such as.

label1.text = &quot;<Script language='javascript'> alert('record was successfully entered into an SQL database') </Script> &quot;

That'l do donkey, that'l do
[bravo] Mark
 
After inserting this code, I get the following error:

Compiler Error Message: BC30648: String constants must end with a double quote.

Any clue?
 
If you are speaking of the code I posted are you sure you haven't turned those single quotes into double quotes. If you are then you need to make the double quotes, double double quotes. Like so.

label1.text = &quot;This is a &quot;&quot;string&quot;&quot; with double quotes in it&quot; That'l do donkey, that'l do
[bravo] Mark
 
I tried double quotes but doesn't work. If I double quote script then script must be declared.
 
The code I gave you. This code
label1.text = &quot;<Script language='javascript'> alert('record was successfully entered into an SQL database') </Script> &quot;

needs to be all on one line. If you use that code as is it should work. That'l do donkey, that'l do
[bravo] Mark
 
Hey Mark,

I tried your code as well, but I couldn't get it to do anything.

i have a label and two buttons. When one button is pressed, it assigns the label's text property to your string. When the second one is pressed, it assigns the same javascript just a different text message for the alert.

When the buttons are pressed, nothing happens on postback though. Is there something else to get the trick working?

Jack
 
Rexxx what did you write this in. I am assuming it wasn't VS?

If you put something like this does it work.
label1.text = &quot;<I am text&quot;

Is this a code behind style page or intermingled? I am going to guess again and say intermingled.

I believe that the compiler is seeing the single quotes in the string as something other than characters in a string. Try placing &quot;&quot; instead of '
label1.text = &quot;<Script language=&quot;&quot;javascript&quot;&quot;> alert(&quot;&quot;record was successfully entered into an SQL database&quot;&quot;) </Script> &quot;

Other than that I am fresh out of ideas for now
That'l do donkey, that'l do
[bravo] Mark
 
Hey Mark,

I tried this code intermingled like Rexx has it and it gives me a Double Quote Error too.

label1.text = &quot;<Script language=&quot;&quot;javascript&quot;&quot;> alert(&quot;&quot;record was successfully entered into an SQL database&quot;&quot;) </Script> &quot;

I have tried several varation which do the same thing. Or it blocks out the word Script and ask you to declare it.
 
I've got it. I also put the code into an intermingled file and got the same error. Looking at it I realized that somehow the compiler was recognizing part of the string as code and not string. I just took the string apart and tried each piece by itself. The problem is with the end script part. If you put this into the label you will find your problem
label1.text = &quot;</Script>&quot;
I figured that the compiler was recognizing a certain sequence of charaters so to fix the problem I just needed to break up those characters. Assuming that </ was the character sequence I broke them up into this
label1.text = &quot;< & &quot;/Script>&quot;

To fix your message box string problem use the following code wherever you need to call a message box.

label1.text = &quot;<Script language=&quot;&quot;javascript&quot;&quot;>alert(&quot;&quot;record was successfully entered into an SQL database&quot;&quot;)<&quot; & &quot;/Script>&quot;

mwahahaha kudos to the codeing genius king Zarcom! That'l do donkey, that'l do
[bravo] Mark
 
That works, now I get a different error message:

System.NullReferenceException: Object reference not set to an instance of an object
 
W00T! that worked for me!

Thanks Mark, you da man. Here's your star

Jack
 
Thanks Jack [bigcheeks]

Rexx, the error you are getting means that you are declaring an object in your code somewhere without the new key word.

Check your dim statments and make sure that they read:
dim something as new object That'l do donkey, that'l do
[bravo] Mark
 
why would it do nothing Mark, Mine does absolutely nothing, no error message, nothing. Can you tell me why it might be doing that?
 
Nevermind Mark I was not calling the subroutine. Hey I also found that if you havea response redirect with this code it doesn't display the message because the client side isn't run before the server side. My little work around.

label1.text = &quot;<Script language=&quot;&quot;javascript&quot;&quot;>alert(&quot;&quot;record was successfully entered into an SQL database&quot;&quot;)<&quot; & &quot;/Script>&quot;
label2.text = &quot;<Script language=&quot;&quot;javascript&quot;&quot;>location.href=&quot;&quot; & &quot;/Script>&quot;
 
Sthmpsn1: Looks like it would work. I didn't check it, since I am sure it would.

Just thought I would make sure you are clear on the client/server thing. That client side script isn't running before the server side because it doesn't exist before the server side code runs. It's only afterwards that the client side exists and can run.

Good job on the work around. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top