DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   message box in c# web application (http://www.daniweb.com/forums/thread116097.html)

ameenu Mar 28th, 2008 5:29 am
message box in c# web application
 
how to implement message box in web application using c#

SheSaidImaPregy Mar 28th, 2008 10:07 am
Re: message box in c# web application
 
register a script for an "Alert":

string str = "function () { alert('OMG ITS me'); }";

Page.RegisterClientScriptBlock("nameofscript", str);

ameenu Mar 31st, 2008 3:12 am
Re: message box in c# web application
 
you have said javascript alert message, but i need server side message using c# code to populate the message box.

Hosam Kamel Apr 4th, 2008 8:16 pm
Re: message box in c# web application
 
Use the below mehtod

public static void ShowMessageBox(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                if (message.EndsWith("."))
                    message = message.Substring(0, message.Length - 1);
            }

            StringBuilder sbScript = new StringBuilder(50);
            //Java Script header
            sbScript.Append("<script type='text/javascript'>" + Environment.NewLine);
            sbScript.Append("// Show messagebox" + Environment.NewLine);
            message = message.Replace("\n", "\\n").Replace("\"", "'");
            sbScript.Append(@"alert( """ + message + @""" );");
            sbScript.Append(@"</script>");         
            // Gets the executing web page
            Page currentPage = HttpContext.Current.CurrentHandler as Page;
            // Checks if the handler is a Page and that the script isn't already on the Page
            if (currentPage != null && !currentPage.ClientScript.IsStartupScriptRegistered("ShowMessageBox"))
            {
                currentPage.ClientScript.RegisterStartupScript(typeof(Alert),"ShowMessageBox", sbScript.ToString());
            }
        }

vishakha_ate Apr 7th, 2008 3:46 am
Re: message box in c# web application
 
if you want to give message box without script than you can insert the snippet of mbox..

csharpdeveloper Aug 18th, 2008 5:11 am
Re: message box in c# web application
 
how do i use the snippet without the script..
plz. urgent requirement...

csharpdeveloper Aug 18th, 2008 5:29 am
Re: message box in c# web application
 
Quote:

Originally Posted by Hosam Kamel (Post 577494)
Use the below mehtod

public static void ShowMessageBox(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                if (message.EndsWith("."))
                    message = message.Substring(0, message.Length - 1);
            }

            StringBuilder sbScript = new StringBuilder(50);
            //Java Script header
            sbScript.Append("<script type='text/javascript'>" + Environment.NewLine);
            sbScript.Append("// Show messagebox" + Environment.NewLine);
            message = message.Replace("\n", "\\n").Replace("\"", "'");
            sbScript.Append(@"alert( """ + message + @""" );");
            sbScript.Append(@"</script>");         
            // Gets the executing web page
            Page currentPage = HttpContext.Current.CurrentHandler as Page;
            // Checks if the handler is a Page and that the script isn't already on the Page
            if (currentPage != null && !currentPage.ClientScript.IsStartupScriptRegistered("ShowMessageBox"))
            {
                currentPage.ClientScript.RegisterStartupScript(typeof(Alert),"ShowMessageBox", sbScript.ToString());
            }
        }



Itz giving me this error....

Error 1 The type or namespace name 'Alert' could not be found (are you missing a using directive or an assembly reference?)

plz. help urgent...
thanx

bheeks Aug 19th, 2008 3:22 am
Re: message box in c# web application
 
http://www.codeproject.com/KB/webfor...leControl.aspx


All times are GMT -4. The time now is 7:39 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC