473,581 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 29178
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 RegisterStartup Script
method on the Page class.

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

"Don" <Do*@don.com> wrote in message
news:u7******** ******@TK2MSFTN GP10.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(sM essage).
--
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.C ount <= 0)
{
//Display Window.Alert("e mpty 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******** ******@TK2MSFTN GP10.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.C ount <= 0)
{
sMessage = "Employee doesn't exist";
Response.Write( "<script language='javas cript'> {
window.alert(sT ext) }</script>");
return;
}

"Don" <Do*@don.com> wrote in message
news:u7******** ******@TK2MSFTN GP10.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.C ount <= 0)
{
//Display Window.Alert("e mpty 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
RegisterStartup Script 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(o bject sender, System.EventArg s e)
{
//code to display a Messagebox here that says "Hello worlld"
}

"Tom Porterfield" <tp******@mvps. org> wrote in message
news:eM******** ******@TK2MSFTN GP10.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.C ount <= 0)
{
//Display Window.Alert("e mpty 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
RegisterStartup Script 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(o bject sender, System.EventArg s 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.EventArg s e)
{
RegisterStartup Script("webButt onClick", "<script
language=\"java script\">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(objec t sender, System.EventArg s e)
{
webButton.Attri butes.Add("oncl ick", "javascript:win dow.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.Ravichandra n
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandra n+J.V.&cob=aspn etpro
- 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.Ravichandr an"
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
30134
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.) and would like to make the dialog look and act like the standard MessageBox. Therefore, I would like to put in the message section the same type of...
3
22190
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 object {User.Path.ToString()});}
6
3229
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 entry application. The code below gets line items from a SQL Server database and returns them to a datagrid by way of a DataTable called...
9
424
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 question text are displayed in bound textboxes. This part works fine. When I go to add a new record, the textboxes clear as they should. I enter a...
3
2681
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, however, it does not work. It does not give me even an error message, but the screen is just freezed (it is running open the page). What are the...
3
6490
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, but with no luck. I have an aspx page where the user enters a bunch of data and clicks 'Submit'. When the user clicks on the 'Submit', I want to run...
3
1989
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 created new custom button called "My Custom Button" in the Outlook menu bar. But when I tried to create one more button called "Forward Mail" (code...
3
4147
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 this is very annoying. So, I added a messagebox to my hidden StartAppForm in the Unload event. Now when the application closes the user is...
7
11102
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 'System.Windows.Application' threw an exception."} {"The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception."} " at...
0
7876
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.