Using msgBox in ASP.NET

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
tariqanisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomasgruenerCommented:
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
tariqanisAuthor Commented:
Hi tomasgruener:
Thanks for the tip. But is there an easy way to use JavaScript alert with an Asp.Net server control?
0
tomasgruenerCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

tariqanisAuthor Commented:
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
tomasgruenerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tariqanisAuthor Commented:
Wow.... I think I can use this... thanks, I might come back for more....
0
tariqanisAuthor Commented:
It works
0
tomasgruenerCommented:
Very good ;) glad I could help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.