Solved

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

Posted on 2014-12-22
7
292 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
  • 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:Michael74
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:Michael74
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:
Michael74 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now