Solved

How to display an alert dialog when running code in C# at Server?

Posted on 2014-12-22
7
312 Views
Last Modified: 2014-12-26
Hi, I'm using VS2012, C# and ASP.NET

When a variable is test null, what's the easiest way to pop up an alert dialog to user with a OK button?  After user click the OK button, can it return to continue the C# code at server?

Thank you.
0
Comment
Question by:lapucca
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40514086
IMHO this is not possible a popup alert runs in the client and the test run in the server. You must check the variable before sending data to the server.
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 40514097
0
 

Author Comment

by:lapucca
ID: 40514126
I would think there is a way to call up client side jquery or javascript alert messagebox from C#.  I just don't know how to do it.  In my C# code if a variable is tested null then I would like to give a pop up message to users and then I would like to reload the current page when users clicks ok on the pop up messagebox.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 23

Expert Comment

by:Michael Fowler
ID: 40514282
Have a look at this link
http://www.aspsnippets.com/Articles/Show-Alert-Message-in-ASPNet-from-Server-Side-using-C-and-VBNet.aspx

  string message = "Zero entered.";
  System.Text.StringBuilder sb = new System.Text.StringBuilder();
  sb.Append("<script type = 'text/javascript'>");
  sb.Append("window.onload=function(){");
  sb.Append("alert('");
  sb.Append(message);
  sb.Append("')};");
  sb.Append("</script>");
  ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());

Open in new window

0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40515075
@Michael74 the code from the article launch the alert message from Page_Load event that means you will launch the popup every time  you load the page.

@lapucca you CAN NOT send the alert to the client, stop server code execution, wait for user response and then awake the server thread and continue. This is not how the client/server architecture works.

You must check the user input for null BEFORE sending the data to the server.
Or depending on the framework you are using you can send validation results back to the client.
0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 500 total points
ID: 40515831
The example shows how an alert can be displayed from an event in this case the page load event. Just change this to the button click event
0
 

Author Closing Comment

by:lapucca
ID: 40519197
Thank you.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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