473,406 Members | 2,619 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,406 software developers and data experts.

Adding MessageBox to web application

Don
How can I add a Messagebox to my web application?
I have a datatable in my web application and I'd like to show a messagebox
when the table's empty.

Thanks.
Nov 16 '05 #1
8 29168
Don,

In this case, you would have to inject script into the response stream
to show a messagebox. You want to call the alert method on the window
object that is exposed to the browser script through JavaScript.

You register your script in ASP.NET by calling the RegisterStartupScript
method on the Page class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Don" <Do*@don.com> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
How can I add a Messagebox to my web application?
I have a datatable in my web application and I'd like to show a messagebox
when the table's empty.

Thanks.

Nov 16 '05 #2
Don wrote:
How can I add a Messagebox to my web application?
I have a datatable in my web application and I'd like to show a messagebox
when the table's empty.


In javascript use window.alert(sMessage).
--
Tom Porterfield
Nov 16 '05 #3
Don
Thanks for the info.

I'm not very familiar with Javascript. For example, in my CSharp code I ask:
if (myTable.Rows.Count <= 0)
{
//Display Window.Alert("empty table");
}

I'm not sure where to put this Window.Alert();
Is it in the .aspx code or the csharp code?

"Don" <Do*@don.com> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
How can I add a Messagebox to my web application?
I have a datatable in my web application and I'd like to show a messagebox
when the table's empty.

Thanks.

Nov 16 '05 #4
Don
I think I have it, but it doesn't display the alert:

if (myTable.Rows.Count <= 0)
{
sMessage = "Employee doesn't exist";
Response.Write("<script language='javascript'> {
window.alert(sText) }</script>");
return;
}

"Don" <Do*@don.com> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
How can I add a Messagebox to my web application?
I have a datatable in my web application and I'd like to show a messagebox
when the table's empty.

Thanks.

Nov 16 '05 #5
Don wrote:
Thanks for the info.

I'm not very familiar with Javascript. For example, in my CSharp code I ask:
if (myTable.Rows.Count <= 0)
{
//Display Window.Alert("empty table");
}

I'm not sure where to put this Window.Alert();
Is it in the .aspx code or the csharp code?


If you want to do it in C Sharp, then do as Nicholas suggests and use
RegisterStartupScript block. If you want to do this without using C
Sharp then you would need to put the some logic in the javascript in
your aspx file to determine when to show the message.
--
Tom Porterfield
Nov 16 '05 #6
Don
Thanks for the example but I'm really not sure of what you're trying to tell
me. Let's say I have a button in my web application and I want to display a
MessageBox, what would I need to add in my C Sharp code (not the aspx file)
?

private void Button2_Click(object sender, System.EventArgs e)
{
//code to display a Messagebox here that says "Hello worlld"
}

"Tom Porterfield" <tp******@mvps.org> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Don wrote:
Thanks for the info.

I'm not very familiar with Javascript. For example, in my CSharp code I ask: if (myTable.Rows.Count <= 0)
{
//Display Window.Alert("empty table");
}

I'm not sure where to put this Window.Alert();
Is it in the .aspx code or the csharp code?


If you want to do it in C Sharp, then do as Nicholas suggests and use
RegisterStartupScript block. If you want to do this without using C
Sharp then you would need to put the some logic in the javascript in
your aspx file to determine when to show the message.
--
Tom Porterfield

Nov 16 '05 #7
Don wrote:
Thanks for the example but I'm really not sure of what you're trying to tell
me. Let's say I have a button in my web application and I want to display a
MessageBox, what would I need to add in my C Sharp code (not the aspx file)
?

private void Button2_Click(object sender, System.EventArgs e)
{
//code to display a Messagebox here that says "Hello worlld"
}


What you need to understand is that there is no way to do this without
client side script. The decision to make is where do you put that
script. You can either put it directly in the aspx file or you can
write some C# code that will inject the script into the response stream
that gets sent to the browser. You must understand that fundamental
concept in order to continue.

There are helper functions in the .NET framework that can aid you in
injecting javascript into the response stream.

If you wanted to put it in your server side click handler it might look
as follows:

private void webButton_Click(object sender, System.EventArgs e)
{
RegisterStartupScript("webButtonClick", "<script
language=\"javascript\">window.alert('you clicked the button');</script>");
}

If the action isn't going to change based on dynamic content that can
only be determined server side after the button is clicked, then it
would be more efficient to either modify the aspx file directly, or add
an attribute to the button in your Page_Load event. Ex:

private void Page_Load(object sender, System.EventArgs e)
{
webButton.Attributes.Add("onclick", "javascript:window.alert('you
clicked the button');");
}
--
Tom Porterfield
Nov 16 '05 #8
I am sure you mean that you want to display a message in a box, which
you could do so with the help of the alert function of Javascript

alert("Some Message");

MessageBox is an object of the windows application domain and hence,
cannot be used in the web model.
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
3
by: Andy_Alpha | last post by:
Here's code,that i think,add user in group .... DirectoryEntry grp=new DirectoryEntry(GroupName); MessageBox.Show(GroupName,"group to add"); try { if (grp!=null) { grp.Invoke("Add",new...
6
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order...
9
by: Greg | last post by:
Binding Manager & dataset - won't add record I've got an untyped dataset with controls bound through code. The user can select a question number from a bound combobox, and the question number and...
3
by: Kiyomi | last post by:
Hello, I use in my application MessageBox.Show and it works perfectly when I run this application on my local computer (http://localhost). When I diployed this application on the server,...
3
by: VMI | last post by:
I know this isn't the best group to post aspnet question, but the MS asp.net NG hasn't been very helpful lately. I've been trying to add a messagebox following the examples I've seen on the web,...
3
by: Kannan | last post by:
Hi, I am trying to created Outloook Add-in Com in outlook using C#. I have seen this URL for developing this sample http://support.microsoft.com/?kbid=302901 When I executed this program it...
3
by: rdemyan via AccessMonster.com | last post by:
Sometimes users (including myself) accidentally click on the application close icon in the application menu bar when they meant to just click on the 'X' for the form. Of course the app closes and...
7
by: moondaddy | last post by:
I'm running a wpf windows app and want to add the appSettings element to the config file. when I do, the app wont start up and I get the following error: {"The type initializer for...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.