467,876 Members | 1,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

How to Create a Message box in ASP.Net

64KB
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
  • viewed: 23084
Share:
1 Comment
hrothenb
'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

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Tingo | last post: by
4 posts views Thread by I_AM_DON_AND_YOU? | last post: by
10 posts views Thread by Zack Sessions | last post: by
5 posts views Thread by Ikkezelf | last post: by
3 posts views Thread by kvadro | last post: by
5 posts views Thread by Laetitia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.