swine Posted November 7, 2012 Share Posted November 7, 2012 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 comment Share on other sites More sharing options...
justsomeguy Posted November 7, 2012 Share Posted November 7, 2012 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 comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now