showing a messagebox from serverside

Posted on 2011-05-02
Last Modified: 2012-05-11
hello guys,

I read few articles but did not come up with a really good idea of how to show something like messagebox or alertbox from the server side.

Any suggestions?
Question by:TheCommunicator
    LVL 11

    Accepted Solution

    This is not a good idea because a message box is a blocking command (as well as being a Windows Forms thing) which will make your application hold until someone responds to the message. Because it's a server there's probably no-one sitting in front of it.

    You can generate some javascript to pop messages up on the client (using alert for instance).
    LVL 10

    Assisted Solution

    Response.write('<script type=\"text/javascript\">alert('My Message Here');</script>");

    Depending on your callback type, response.write may not be the best option.  Take a look also at the clientscript object, with RegisterStartupScript() or RegisterClientScriptBlock().  These methods do NOT work well with AJAX type calls, including using the update panel.

    LVL 29

    Assisted Solution

    by:Paul Jackson
    I have a serverside function like this :
       ''' <summary>
        ''' add client-side message box
        ''' </summary>
        ''' <param name="aspxPage"></param>
        ''' <param name="strMessage"></param>
        ''' <param name="strKey"></param>
        ''' <remarks></remarks>
        Public Shared Sub CreateMessageAlert(ByRef aspxPage As System.Web.UI.Page, _
                                            ByVal strMessage As String, _
                                            ByVal strKey As String)
                Dim strScript As String = "<script language=JavaScript>alert('" & strMessage & "')</script>"
                Dim cs As ClientScriptManager = aspxPage.ClientScript
                If (Not cs.IsStartupScriptRegistered(strKey)) Then
                    cs.RegisterStartupScript(aspxPage.GetType(), strKey, strScript)
                End If
            Catch ex As Exception
            End Try
        End Sub

    Open in new window

    which is then called like this in the behind-code :
    CreateMessageAlert(Page, "This is some message text", "errorMessageKey")

    The script is then registered and shown on redisplay.
    LVL 40

    Assisted Solution

    Whether you generate from server-side or client-side, you can use a framework like ExtJS that will give you nice messag boxes without blocking the browser as brutaldev says. The blocking alert is annoying to users. (now renamed to Sencha)

    But it is a large framework to learn, so you could try the JQuery message box plugin.


    Author Comment

    Hi Guys,

    I am so sorry for being lazy and late reply. So what I wound up doing was this.

    I used a DIV and made it look like a message box. I toggle it's visibility whenever required. Set its Z-index to 1. I know it's not the most efficient way to do it but just wanted to save sometime by finishing up everything on server side because my client side programming always sucks....

    LVL 10

    Assisted Solution

    If you're doing that I would recommend that you have everything else in a separate panel which you can disable.  This will make the popup modal for you.


    Author Comment

    Yes, it exactly looks like Popup _modal, which makes sense though considering the purpose of the window because I am using this messge box to show the session time out messages.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    The viewer will learn how to dynamically set the form action using jQuery.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now