By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,403 Members | 1,567 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

How to Create a Message box in ASP.Net

P: 85
people face lot of problems in creating message boxes like in desktop applications in asp.net, there are lot of ways of calling javascript alerts, but here i would explain how to generate a message box in asp.net..
for that , create a class and name it Messages.cs in App_Code. the class will have a single method to generate the message box like as follows
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7.  
  8. /// <summary>
  9. /// Summary description for Messages
  10. /// </summary>
  11. public class Messages
  12. {
  13.     public Messages()
  14.     {
  15.         //
  16.         // TODO: Add constructor logic here
  17.         //
  18.     }
  19.  
  20.  
  21.     public void CreateMessageAlert(string strMessage)
  22.     {
  23.         Guid guidKey = Guid.NewGuid();
  24.         Page pg = (Page)HttpContext.Current.Handler;
  25.         string strScript = "alert('" + strMessage + "');";
  26.         pg.ClientScript.RegisterStartupScript(pg.GetType(), guidKey.ToString(), strScript, true);
  27.     }
  28. }
  29.  
  30.  
now in your page where ever you want to display an OK message box , you can call like this
Expand|Select|Wrap|Line Numbers
  1. Messages myMsg=new Messages(); // create the object 
  2. myMsg.CreateMessageAlert("Your Message Here");
  3.  
  4.  
...
Addan
Aug 3 '12 #1
Share this Article
Share on Google+
2 Comments


hrothenb
P: 2
'ASP.net MessageBox
'Add a scriptmanager to the ASP.Net Page

<asp:scriptmanager id="ScriptManager1" runat="server" />


try:

Dim sMsg As String = "My Message"

ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "alert('" & sMsg & "')", True)
Nov 6 '14 #2

P: 18
Hey,I am sharing a link you will get the exact code there:
https://code.msdn.microsoft.com/CSAS...geBox-3e8c6273

Good Luck
Jan 12 '16 #3