Jump to content

Getting confirm value in code behind


Recommended Posts

Hello, I have a repeater with a hidden button. Using the ItemCommand Event in code behind, I used a MsgBoxStyle.OkCancel asking if user wants to continue his action. If user clicks ok, a stored procedure is called, writing some data in DB. I uploaded the application to the webserver and repleaced the MsgBox with a javascript confirm box in code behind.I'm facing two problems right now. First: How can I access the Ok Click Event from the confirm box? Second: The confirm box appears, but the page reloads as well. How can I prevent the Postback? old:

Dim intAnswer As Integer = MsgBox("Do you wish to continue?", _							  MsgBoxStyle.OkCancel)If intAnswer = vbOK TheninsertData()End If

new:

Page.ClientScript.RegisterStartupScript(Me.GetType, "confirm", "confirm('Do you wish to continue?')",True) 'If user clicks ok insertData()

Thanks for your help.

Link to post
Share on other sites

The confirm method is synchronous, so it will pause Javascript execution until one of the buttons is pressed. The confirm method will either return true or false based on what they pressed. Most people use confirm as the condition in an if statement. The confirm method is native Javascript, so I doubt there is a way to handle that click event server-side without using something like ajax to send that confirmation value to the server. The browser doesn't expose individual events for the buttons in a confirm box, the confirm box is not part of the DOM. In your second piece of code it looks like insertData will always be executed. That server-side code has a line to add some Javascript to run when the page loads, and then it calls insertData. The two aren't related.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...