How to use a messagebox in asp.net

G

Guest

Hi,

I made a small ASP.net web page and in it I used a messagebox to confirm
first before an execution would take place.
It worked fine while testing it locally, but when i published it on a server
it didn't work anymore.

I understand why, but still have the problem that I would like the user to
confirm first before execution begins.

How is it done?
I searched a bit and found javascript solution but how do I fit them in my
code?

My code looks something like this :
Dim somethings
result = MsgBox(MsgText.ToString, MsgBoxStyle.YesNo +
MsgBoxStyle.MsgBoxSetForeground, "title")

If result = vbYes Then
start execution
Else
some code
End If
 
D

David Wier

What do you have behind the MsgBox?
Are you using Javascript in another routine?
There is no ASP.Net intrinsic control like this - however there is a
ConfirmButton in the Ajax toolkit.
 
A

Aidy

How is it done?

You don't. If you want user interaction it has to be done via javascript on
the client, not server-side code. If you use message boxes in asp.net code
the box appears on the server and no-one is there to click it, certainly not
the intented client.
 
G

Guest

What do you have behind the MsgBox?

What do you mean?
I have a page where you have to give a month (text box) and select a value
from a listbox.
The messagebox shows in its text both values and asks for confirmation
(that's what i would like it to do)
You can eather cancel it and nothing happens or click ok and execution
begins for the values selected.

Are you using Javascript in another routine?
No

There is no ASP.Net intrinsic control like this - however there is a
ConfirmButton in the Ajax toolkit.

Is this a tool that you just install and use?
 
G

Guest

Aidy said:
You don't. If you want user interaction it has to be done via javascript on
the client, not server-side code. If you use message boxes in asp.net code
the box appears on the server and no-one is there to click it, certainly not
the intented client.

Yes i already know that i cannot use "msgbox" but the above question was how
can i let the user confirm it.

The messagebox text is assembled by input the user gave. The user should
confirm first before a calculation begins
 
M

Mark Rae

Yes i already know that i cannot use "msgbox" but the above question was
how
can i let the user confirm it.

<script type="text/javascript">

function confirmCalc()
{
return confirm('Are you sure you want to run this calculation?');
}

</script>

Eliyahu has already given you a link to a site which explains how to use
this...
 
A

Aidy

Use a javascript function. I believe it is called Confirm, it pops up a
Yes/No type box, and if the user clicks Yes you submit the form, if they
click No you don't.
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

Here's some server side code that uses JavaScript to display a confirmation
message.

MyDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx
 
A

Aidy

I see that kind of code a lot, personally I would recommend against it. Why
put client-side code in your code behind? Changing it requires a re-compile
and re-release. Just put the code direct in the HTML.

Steve C. Orr said:
Here's some server side code that uses JavaScript to display a
confirmation message.

MyDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called
in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx
 
M

Mark Rae

I see that kind of code a lot, personally I would recommend against it.
Why put client-side code in your code behind? Changing it requires a
re-compile and re-release. Just put the code direct in the HTML.

I disagree entirely!!! You're not seriously suggesting that the ability to
hack about with aspx files just because they're not compiled is actually a
"good thing"...?

Projects without proper change control procedures are doomed to failure,
IMO...
 
M

Mark Rae

Here's some server side code that uses JavaScript to display a
confirmation message.

MyDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

And just to add to this, in ASP.NET 2 buttons have an OnClientClick
property:

MyDeleteButton.OnClientClick = ""return confirm('Are you sure you want to
delete?');";
 
A

Aidy

I disagree entirely!!! You're not seriously suggesting that the ability to
hack about with aspx files just because they're not compiled is actually a
"good thing"...?

Yes, yes I am.

Compare changing an aspx file and uploading vs changing a cs file,
re-compiling, re-uploading and resetting the application and booting
everyone off.
 
A

Aidy

Wow! What a pro...:)

*shrug* I'm a realist and a purist. Client code should go on the client.
 
M

Mark Rae

Ok, client code should be entered at the client level.

Where the client code is entered is totally and utterly irrelevant as far as
the browser is concerned - my point was that you appear to believe that
hacking about with aspx files is acceptable, and I don't...

No biggie... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top