?
Solved

Using msgBox in ASP.NET

Posted on 2008-11-11
8
Medium Priority
?
675 Views
Last Modified: 2013-11-26
Hi,
When I use a msgBox in ASP.Net 2 the message doesn't pop up in the center of the screen as it does in regular visual basic applications but shows up like a minimized window on the task bar.
Is there a way to correct this?
Thanks
0
Comment
Question by:tariqanis
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:tomasgruener
ID: 22932724
Can't help you with your problem, but maybe I can save you some trouble... Do you try to popup a MsgBox on the client (so the viewer of the page)? if so, don't use msgbox.
MsgBox is a WinForm control and gets displayed on the server. that means you see the msg box on the server, and all further operation is cancelled, until you click on it.... usually a client can't access the server, this means, that the web application will break.
if you want to display a msgbox to the client, use Javascripts alert.
0
 

Author Comment

by:tariqanis
ID: 22932790
Hi tomasgruener:
Thanks for the tip. But is there an easy way to use JavaScript alert with an Asp.Net server control?
0
 
LVL 2

Expert Comment

by:tomasgruener
ID: 22932963
Depends on what you want to do... Just to show an example (i show it in c#, don't know the vb.net syntax). Lets say, you have a select on your screen, where you added the runat="server" tag with the id "customerSelect".
Now you can do following:
customerSelect.Attributes.Add("onchange", "alert('You changed the value')");

you could also add it directly to the html markup like this:
<select onchange="alert('You cangeng the value')">

But if you do it in the markup, you don't have control over the call... if you do it on the server side, you could create an outputstring like you need it (for example to include server time in the message)

If you don't get it, the best thing would be to create an empty page and just test this thing... its very simple, once you got it
//Code
customerSelect.Attributes.Add("onchange", "alert('You changed the value')");
 
<!-- Markup -->
<select onchange="alert('You cangeng the value')">

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tariqanis
ID: 22933281
I am sorry I don't get it.....
What is not clear to me is where to place the code if I am using Asp.net mark up:
Let us say I have a button (call it button1), the original mark up will be in the following way:

<asp:button id="button1" runat="server" />

In a case like the above where do I place your code?


0
 
LVL 2

Accepted Solution

by:
tomasgruener earned 2000 total points
ID: 22935071
Ok, thats basic material in web developement. to give you an overview:
you have two sides. one thing is the server part, which generates output, handles state, authenticates user and so on. the code runs on the server itself. it has access to the servers resources.
the second part is the client side code (like javascript). this code runs on the client. every browser has its own js engine, to parse the code, but its the browser, that does stuff, without requiring connection to the server.
so the thing you want to know. there are several places, where you could put your code. i prefer creating *.js files in a scripts folder in the app and include them in the masterpage. to include js files, you can put following tag into your head element in your page:
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/foo.js") %>"></script>

This little line includes the script, but you can put also script tags everywhere in the html code, but I prefer putting custom code also in the header.
<script type="text/javascript">
function foo()
{
alert("bar");
}
</script>

Then you can also put js code into html elemelt events. this means, that every html element has some events, like onclick, where you can attach to. this would look something like this:
<a href="#" onclick="foo()">Click Me Not</a>

Now you just have to decide, if its enough to do a simple inlen alert to display a message, or if you want to create a function, that determines the state of the app and gives an specific message...

hope it helps
//Script Include
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/foo.js") %>"></script>
 
//Script in File
<script type="text/javascript">
function foo()
{
alert("bar");
}
</script>
 
<!-- Inline Script (in HTML Markup -->
<a href="#" onclick="foo()">Click Me Not</a>

Open in new window

0
 

Author Comment

by:tariqanis
ID: 22935594
Wow.... I think I can use this... thanks, I might come back for more....
0
 

Author Comment

by:tariqanis
ID: 22935597
It works
0
 
LVL 2

Expert Comment

by:tomasgruener
ID: 22937735
Very good ;) glad I could help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 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