?
Solved

The best way to show messages to user

Posted on 2010-08-15
13
Medium Priority
?
981 Views
Last Modified: 2012-06-27
Hi!

In my website I'm using a Panel with a Label inside to show confirmation messages to user.
For e.g.
When the user fails the login, I set
Panel.visible = true;
Label.Text = "Login Failed";

Sometimes gets hard to handle the panel to visible/invisible.

It does works but I think that is not the better (or prettier) way to do that.

Any suggestions? Maybe some Ajax/JQuery showing the message just for a few seconds...

Thanks in advance!
0
Comment
Question by:calypsoworld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 18

Expert Comment

by:Gary Davis
ID: 33442176
Just set Label.Text to your error or empty if no error. Then you don't need a panel and don't need to set any visible property.
Gary
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 33442188
You could try something like this in the attached code snippet.

From C# codebehind for example, you would call it by:

string messageText = "Hello there!";

StringBuilder sb = new StringBuilder()
sb.AppendLine("<script type=\"text/javascript\">");
sb.AppendLine("showMessage(\"" + messageText + "\"");");
sb.AppendLine("</script>");

Page.ClientScript.RegisterStartupScript(Page.GetType(), "key", sb.ToString());
function showMessage(text)
{
    var msgBox = document.getElementById("divMessage");
    if (msgBox)
    {
        msgBox.innerHTML = text;
        msgBox.style.display = "";
        setTimeout("hideMessage()", 5000);
    }
}
function hideMessage()
{
   var msgBox = document.getElementById("divMessage");
   msgBox.style.display = "none";
}

Open in new window

0
 
LVL 7

Expert Comment

by:Gewgala
ID: 33442195
Forgot to clarify, in the above, the code snippet is Javascript, and it will display your div box for 5 seconds (5000 milliseconds) and then it will hide it automatically afterward.  The top code example above the snippet is how you would execute the javascript using C#.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:Adam Menkes
ID: 33442201
0
 

Author Comment

by:calypsoworld
ID: 33442206
Thank you for reply.

I need a Panel to make the message more attractive. If it's just a label appears, maybe user can't see it.

In a GridView, click on a button that returns me a message, this message appears. Ok.
But if I still using the GridView, this message keeps visible, so I put this code on page load method.

(isPostBack) Label.Text = ""

Ok, it works. But there is nothing easier or ''prettier'' ?


Thank you!
0
 
LVL 19

Assisted Solution

by:Adam Menkes
Adam Menkes earned 664 total points
ID: 33442226
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 33442247
My way could be used to make it pretty, you just have to style your div properly.  The div will appear and then disappear after 5 seconds like you were saying.
0
 

Author Comment

by:calypsoworld
ID: 33442278
> Gewgala

The C# code that you posted, must be placed on page load method?

How should I call the JavaScript method showMessage(text) from C#?

Thank you!
0
 
LVL 7

Assisted Solution

by:Gewgala
Gewgala earned 664 total points
ID: 33442406
You can put it in a method, such as the attached snippet.  Then just call it whenever you want to display the message.  Anywhere in your code, if you have the below snippet in your codebehind file:

// some code...

ShowMessage("Your information was saved successfully!");

// some more code...



protected void ShowMessage(string message)
{
     string messageText = "Hello there!";

     StringBuilder sb = new StringBuilder()
     sb.AppendLine("<script type=\"text/javascript\">");
     sb.AppendLine("showMessage(\"" + message + "\"");");
     sb.AppendLine("</script>");

     Page.ClientScript.RegisterStartupScript(Page.GetType(), "key", sb.ToString());
}

Open in new window

0
 
LVL 7

Expert Comment

by:Gewgala
ID: 33442413
Forgot to erase this line:

string messageText = "Hello there!";

from my previous post in the attached snippet.  I copied and pasted the example from before into the method body.  The messageText variable is no longer necessary since the message being passed in is a parameter, and you're just plugging in the parameter to the javascript function call.
0
 
LVL 14

Accepted Solution

by:
robasta earned 672 total points
ID: 33443674
also, consider using the ajaxcontroltoolkit modalpopup - here is an example for a gridview (the site has many useful examples for the control) http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html
0
 

Author Comment

by:calypsoworld
ID: 33563194
Thank you for replies!

I have not tested all the solutions yet.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

743 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