473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

ASP.NET, C# and MessageBoxes

How do I get the browser to display a message box using C# in ASP.NET?

Something similar to Javascripts Alert( ) type messagebox...
Nov 16 '05 #1
3 3442
"Tony" <To**@discussions.microsoft.com> wrote in message news:83**********************************@microsof t.com...
How do I get the browser to display a message box using C# in ASP.NET?
Something similar to Javascripts Alert( ) type messagebox...


The solution is to render some client-side script to the end user's browser,
using Page.RegisterClientScriptBlock( ) with some JavaScript, as you say,
that calls alert( ).

In the Page_PreRender event handler, for example,

// . . .
string jsAlert = "<script language=\"Javascript\"><!-- alert( \"Hello World!\"); --></script>";
Page.RegisterClientScriptBlock( "myScriptBlock", jsAlert);
// . . .
Derek Harmon
Nov 16 '05 #2
ASP.NET is a server side technology and displaying a messagebox from the C# code would be worse than useless as no-one will see it *and* it would block a server side thread waiting for never-arriving user input. The way to display a message box to the client is to issue a ...

Javascript Alert into the rendered page.

If this is something you will do frequently then create a server side control that emits the necessary javascript in its CreateClientSideScriptBlock. Otherwise just emit it using Response.Write

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<83**********************************@microsoft.co m>

How do I get the browser to display a message box using C# in ASP.NET?

Something similar to Javascripts Alert( ) type messagebox...

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #3
Ok - So I created my script - but how do I call it from my C# event handler
Thanks
Tony

"Derek Harmon" wrote:
"Tony" <To**@discussions.microsoft.com> wrote in message news:83**********************************@microsof t.com...
How do I get the browser to display a message box using C# in ASP.NET?
Something similar to Javascripts Alert( ) type messagebox...


The solution is to render some client-side script to the end user's browser,
using Page.RegisterClientScriptBlock( ) with some JavaScript, as you say,
that calls alert( ).

In the Page_PreRender event handler, for example,

// . . .
string jsAlert = "<script language=\"Javascript\"><!-- alert( \"Hello World!\"); --></script>";
Page.RegisterClientScriptBlock( "myScriptBlock", jsAlert);
// . . .
Derek Harmon

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Boomessh | last post by:
Hai all, I am working on a C# 3 tier application. I want to make all MessageBoxes appear in the local language (currently the Messageboxes appear in English). In what way can i implement this,...
2
by: Claire | last post by:
I need my communication status window to be topmost when it's open/active. Ive set the TopMost property of the form to true and it does work ok. After performing tasks this window generates an...
0
by: Robert W. | last post by:
I read this and am a bit confused: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsMessageBoxClassTopic.asp If I display a messagebox from...
0
by: luna | last post by:
need a basic message box - that when an exit button is pressed it checks the state of a variable if its true then it exits - if its false then a message pops up saying you havent saved - are you...
4
by: Carlos | last post by:
Hi all, I am new to asp in general, and I would like to know if it is good practice just to display a messagebox after a form validation is performed and the user must be warned about missing...
3
by: Tim Osborne | last post by:
Hi I am currently investigating a very annoying problem with one of our applications. We have a UserControl that runs in IE. As the control fires up the constructor does some status...
2
by: Rudy | last post by:
Hello all! I'm running a fileWatch on a file. When the the file has a LastWrite, it will prompt a message box. Only looking at that file, and no Sub Directories. Private Sub...
1
by: zimdanen | last post by:
I am trying to use NUnit for testing, at the insistence of a coworker. In order to test the code, I are using an MDI (also at the insistence of that coworker) so that I can get to the forms that I...
2
by: mahesh123 | last post by:
Hi, I want to display messages in my asp.net pages.i kept Msgbox().But it is working only in the localhost.After uploading it is not working.I think it is server side thats why it is not showing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.