?
Solved

showing a messagebox from serverside

Posted on 2011-05-02
7
Medium Priority
?
373 Views
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?
0
Comment
Question by:TheCommunicator
7 Comments
 
LVL 11

Accepted Solution

by:
brutaldev earned 400 total points
ID: 35507110
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).
0
 
LVL 10

Assisted Solution

by:GeoffSutton
GeoffSutton earned 800 total points
ID: 35507195
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.

HTH,
Geoff
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 400 total points
ID: 35507253
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)
        Try
            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
            Throw
        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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 400 total points
ID: 35507255
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.

http://www.extjs.com (now renamed to Sencha)

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


0
 

Author Comment

by:TheCommunicator
ID: 35730954
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....

Thanks
0
 
LVL 10

Assisted Solution

by:GeoffSutton
GeoffSutton earned 800 total points
ID: 35730982
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.

Geoff
0
 

Author Comment

by:TheCommunicator
ID: 35731356
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.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 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