confirm in asp.net

B

Betina Andersen

Hi

I am using vb in asp.net and I need to have a confirm in the middle of my
code(code-behind), but cannot get the confirm to display when I want it, but
it comes when my button has ended it code, any help appriciated.

Sub Button_Click
<code>
..
..
Dim scriptString As New StringBuilder
scriptString.Append("<script language='javascript' type='text/javascript'>")
scriptString.Append("var ok=confirm('Budget findes i forvejen - Ønskes det
overskrevet?\n" & strIkkeKopieret & "');" & "document.getElementById('" &
Skjult.ClientID & "').value=ok;")
scriptString.Append("</")
scriptString.Append("script>")
ScriptManager.RegisterStartupScript(sender, Me.GetType, "Info",
scriptString.ToString, False)
..
..
<mere kode>
End Sub

Then the box shows here and not where I definded it to? I tries both the
ScriptManager.RegisterStartupScript and
theScriptManager.RegisterClienScriptBlock, I am using Ajax, so it has to be
ScriptManager I have to use, as I understand it.

Regards Betina
 
P

Patrice

You just can't. The programming model is :
- you create an HTML page using server side code
- this HTML pages is rendered by the browser and its client side code (if
any) runs either directly on depending on which client side events are
happening
- eventually this page postback to runs some other server side code
etc...

Usually what you are trying to do is done by asking the question client side
when the button is clicked. You can then cancel the event (and nothing else
happens) or confirm (and then it usually results in a postback where you can
run the server side code that will do the job).

As a side note you may want to try a more focused group such as
microsoft.public.framework.aspnet as this is more an ASP.NET issue than a
specific language issue.
 
C

Cor Ligthert[MVP]

Betina,

As Patrice tells you, you can run on the serverside everything that you want
to do on a page. However you cannot start a process yourself direct on the
clientside, that is something the client has to do and a lot for that is
prevented in the webbrowsers.

(That is exactly the reason that we get so much security updates, because
some people want to do that).

Cor
 
B

Betina Andersen

So what you are saying, it is not possible to aks the user a yes/no question
in the middle of some code and act accordingly to the reply?

Regards Betina
 
P

Patrice

Not in the *middle* of server side code.

The flow should be :
- the user enters the data and press the submit button
- server side code runs and send to the client the client side markup and/or
code that will ask the question to the user (at this point there are nothing
going on server side)
- client side the user answers to the question and press a submit button
- server side code runs etc...

You have to split your server side code in two parts :
- a part that renders the client side dialog
- a part that will be triggered when the client side dialog is answered

A web application is always based on the same principle :
- server side codes runs (and ends)
- the user interact with the markup sent by the server side code and at some
point trigger some server side code going back to step 1

You can't mix server side and client side interaction within the same round
trip
 

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

Top