Tigger, there are a number of ways to approach this.
As Karl and Scott pointed out, there is a very clean way to add a
confirmation dialog to an ASP.NET button, that cancels the postback if you
cancel the dialog. If "myFunction" is a javascript function, you can easily
embed this in your page using the same mechanism they've described. As long
as your function returns true/false, you can use your function to approve
(true) or cancel (false) the button-click operation.
If you need more complex processing, database queries, or for other reasons
want myFunction to be in your .NET codebase, then you will probably be
better off building a WebForm that provides the messagebox-like capability
you desire.
Go with a pattern you're comfortable with. You might do something
wizard-style; a sequence of pages with server-side logic to dictate the
navigation rules. Or you might go with a pop-up HTML page that you style
like a message box. The latter approach will require some javascript to
display the window, and probably some more to refresh your screen or perform
some navigation once the "message box" response is captured.
In short, developing a web app still doesn't come with all the conviences
that Windows application developers are accustomed to. HTTP and HTML were
not originally designed to support apps, but with enough creativity and
research you can still mimic most of the familiar GUI features.
"Tigger" <Tigger@discussions.microsoft.com> wrote in message
news:DC341B89-FF3B-4C10-B7E2-FBB9BA955140@microsoft.com...[color=blue]
> Hello Experts,
> Thanks a lot for your reply. Your example really works but it needs me to
> click a button in order to kick off the action (prompt out a Confirm[/color]
message[color=blue]
> box). How about if I would like to do the following:
> 1) call a function (e.g. myFunction). This function returns a string;
> 2) immediately right after getting the result from myFunction, I would[/color]
like[color=blue]
> to prompt the Confirm message box to the users with the result shown on[/color]
the[color=blue]
> box;
> 3) if the user clicks YES, then go ahead to do some other processing on[/color]
the[color=blue]
> server;
>
> *As you can see, no button is clicked in the above flow. Is it possible to
> do so?
> Please let me know.
> Many thanks.
> Tigger
>
>
> "Karl Seguin" wrote:
>[color=green]
> > I musn't have explained myself or am totally missing something
> >
> > What I got from the question was: "How do I display a yes/no type box[/color][/color]
and[color=blue][color=green]
> > when "yes" is clicked proceed to do some processing (presumably on the
> > server side)"
> >
> > My solution was something along the lines of:
> >
> > <HTML>
> > <body>
> > <form id="Form1" method="post" runat="server">
> > <asp:Button ID="delete" Runat="server" />
> > </form>
> > </body>
> > </HTML>
> > <script runat="server">
> > public sub page_load
> > delete.Attributes.Add("onClick", "return confirm('are you[/color][/color]
sure?');")[color=blue][color=green]
> > AddHandler delete.Click, AddressOf Delete_Clicked
> > end sub
> >
> > private sub Delete_Clicked(sender as object, e as EventArgs)
> > Response.Write("HERE!")
> > end sub
> > </script>
> >
> >
> > which indeeds work. Perhaps what I was missing was the AddHandler, but[/color][/color]
I[color=blue][color=green]
> > don't know how Tigger prefers to set up his events and figured it was[/color][/color]
kinda[color=blue][color=green]
> > self-evident (since I did use an asp:button after all) so I left it out
> > (note however that I did point to a more complete tutorial).
> >
> > I'm not really sure how your idea of creating your own hidden variables[/color][/color]
and[color=blue][color=green]
> > your own submission code is any better than this.
> >
> > Anyways, I might be out to lunch...
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> >
http://www.openmymind.net/
> >
> >
> > "Scott M." <NoSpam@NoSpam.com> wrote in message
> > news:%23lyoP$49EHA.3472@TK2MSFTNGP14.phx.gbl...[color=darkred]
> > > Your code will not result in the button's server side click event[/color][/color][/color]
being[color=blue][color=green][color=darkred]
> > > handled at all. What you've showed is how to attach a client-side[/color][/color][/color]
event[color=blue][color=green][color=darkred]
> > > handler at the server level.
> > >
> > >
> > >
> > >
> > > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME[/color][/color][/color]
net>[color=blue][color=green][color=darkred]
> > > wrote in message news:%23Ooqcb49EHA.2112@TK2MSFTNGP14.phx.gbl...
> > > > Tigger:
> > > > The easiest way is to use a normal asp:net button and attach a[/color]
> > javascript[color=darkred]
> > > > event to it:
> > > >
> > > > <asp:button id="delete" runat="server" />
> > > >
> > > > in your codebehind, you do:
> > > >
> > > > Sub Page_Load
> > > > delete.Attributes.Add("onClick", "return confirm('Are you[/color][/color][/color]
sure?');")[color=blue][color=green][color=darkred]
> > > > End Sub
> > > >
> > > > and the processing can happen in the delete's button server-side[/color][/color][/color]
click[color=blue][color=green][color=darkred]
> > > > event...which will only fire if they clicked "ok" in the confirm[/color][/color][/color]
window.[color=blue][color=green][color=darkred]
> > > >
> > > >
http://aspnet.4guysfromrolla.com/articles/021104-1.aspx as the steps[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > greater detail.
> > > >
> > > > Karl
> > > > --
> > > > MY ASP.Net tutorials
> > > >
http://www.openmymind.net/
> > > >
> > > >
> > > > "Tigger" <Tigger@discussions.microsoft.com> wrote in message
> > > > news:31ACD219-BD12-4628-BF14-84A7C30B2FFF@microsoft.com...
> > > >> Dear Experts,
> > > >> I am working on ASP.NET. I have got a problem related to the usage[/color][/color][/color]
of[color=blue][color=green][color=darkred]
> > > >> Javascript in ASP.NET. Please help. The story is the following:
> > > >>
> > > >> 1) I am developing an ASP.NET application. I need to prompt the[/color][/color][/color]
users[color=blue][color=green][color=darkred]
> > > >> with
> > > > a
> > > >> modal box (with "Yes" and "Cancel" button on it);
> > > >> 2) When the user clicks "Yes" button, I need to do some further
> > > > processing.
> > > >> If "Cancel" is clicked, of course, stops doing anything;
> > > >> 3) Now the problems are:
> > > >> - which JavaScript would be appropriate? e.g. confirm,[/color][/color][/color]
showModalDialog,[color=blue][color=green][color=darkred]
> > > > etc.
> > > >> - * How can I catch the click event in ASP.NET codes when the user[/color]
> > clicks[color=darkred]
> > > >> the "YES" or "Cancel" button? This is the most tricky part that I[/color]
> > really[color=darkred]
> > > >> don't know on how to do so! Please kindly help.
> > > >>
> > > >> Thanks a lot.
> > > >> --
> > > >> I am Tigger.
> > > >
> > > >
> > >
> > >[/color]
> >
> >
> >[/color][/color]