Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display msgbox in asp.net(C#) using javascript
Posted

Hi,

For this, you can use the ClientScriptManager of the current page.

Here is an example:

ClientScript.RegisterStartupScript(typeof(_Default), "Message", "alert('Hello World');", true);


Explanation:

ClientScript.RegisterStartupScript(
   <<a type to identify the script source>>,
   <<a unique script identifier, used for not rendering the same script twice>>,
   <<the js code to be pasted in the output rendering>>,
   <<defines if a script tag should be written around your script>>);


Here the explanation from the MSDN: http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx[^]


Hope this helps.

Best regards and happy coding :)
Stops
 
Share this answer
 
The answer you got is right, but only the alert part, is needed to show a message. You could also use the ClientClick event of a button, or any other javascript you may put direct in your ASPX to show a message box, depending on your needs.
 
Share this answer
 
Comments
Christoph Keller 28-Jun-11 1:30am    
Yes, thats true, it was just an example :)

After some research, I found this: jQuery bPopup plugin / bPopup demos, just as a starting point for custom JS Messageboxes.

Hope this helps!

Have a nice day and happy coding! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900