popup error message in asp.net

you guys know that msgbox doesn't work in the asp.net  so what do i do to have a popup message when there's an error. if you have the code also that would be great. thanks.
StewSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TechSingerCommented:
The way I have done this is to use the Javascript command, Alert.   If you need to have the message come up during server side code, ti will cause a repost.
It is much cleaner if can build the whole part of the code that needs the message in Javascript, then it won't require a new post since the code is running on the client side.
0
Bane83Commented:
From javascript, you would use alert.

<script type="text/javascript">
alert("There was an error!");
</script>

You cannot do this directly from ASP.NET, but you can write the script to the page using the ClientScriptManager (I believe the method you need is Page.ClientScriptManager.RegisterClientScriptBlock).  You'll can pass this some javascript like the one above and it will write it to the page and pop up the alert.
0
StewSupportAuthor Commented:
when i tried this code, it doesn't have any pop up at all
Dim tail As String
Dim scs As String
Dim guts As String
 
tail = " </" & "script>" 'Note wierd construct required
guts = "function testing() {confirm('trying script); return false; }"
scs = "<script type='text/javascript'> " & guts & tail
 
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myscript1", scs)

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Bane83Commented:
Right, you put it inside of a function, so you need something to call it.  You can either pull it out of the function or add a line to guts which will call the function, ie:

guts = "function testing() {confirm('trying script); return false; } testing();"
0
StewSupportAuthor Commented:
yes i do have something that call that function but the popup just doesn't pop
0
Bane83Commented:
Ah, I just tried it out and got an unterminated string literal error here:

confirm('trying script);

You're missing the closing quote:

confirm('trying script');
0
StewSupportAuthor Commented:
still doesn't popup on mine
0
Bane83Commented:
Could I see some of the page code?  How are you attempting to call testing()?  Is it on a button click?  Do you use any UpdatePanels on the page?
0
StewSupportAuthor Commented:
i use updatepanel and a button to click. once you click the button it calls the function above which has javascript that calls that the javascript function
0
prairiedogCommented:
>>>i use updatepanel and a button to click. once you click the button it calls the function above which has javascript that calls that the javascript function
So you want to run the server side code first, then the JavaScript code, right?
0
Bane83Commented:
Ah, ok, there's the problem.  If you have an UpdatePanel, you can't use Page.ClientScriptManager.RegisterClientScriptBlock you need to use ScriptManager.RegisterStartupScript
http://msdn.microsoft.com/en-us/library/bb359558.aspx
0
StewSupportAuthor Commented:
yes prairedog i want to run the server side code first then javascript if there's an error.
0
prairiedogCommented:
What do you want to do after displaying the error message?
0
StewSupportAuthor Commented:
just hit ok really.
0
prairiedogCommented:
>>>just hit ok really.
Then what? Stay on the same page or redirect user to another page?
0
StewSupportAuthor Commented:
then stay on the same page.
0
prairiedogCommented:
OK, in your code behind, whereever you find an error, do this:
If (errorFound) Then
   ClientScript.RegisterStartupScript(Me.GetType(), "AlertBox", "alert('Error found.');", True)
Else
   'Continue your work
End If
0
StewSupportAuthor Commented:
nope, i dont see any popup at all.
0
prairiedogCommented:
Can you post your code to let me see where you put the code snippet?
0
StewSupportAuthor Commented:
right at the page load i dont  i was just testing  the code so right when pageload i have the code. nothing else.
0
prairiedogCommented:
You mean like this and it is not working?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
	ClientScript.RegisterStartupScript(Me.GetType(), "AlertBox", "alert('Error found.');", True)
 
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StewSupportAuthor Commented:
yes that is correct
0
prairiedogCommented:
Hmmm, it is strange....it is working with me. Maybe you can post your code here?
0
StewSupportAuthor Commented:
i dont know what it is i reinstalled vb and it worked with your script. thank you for helping.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.