locked
Display confirm box from code behind and get the response from confirm and continue the pending code execution in user control in VB.net web application RRS feed

  • Question

  • User-885259083 posted

    Hi All,

    i am trying to show the confirm box using javascript.

    there is home page in that page i am having the user controls standardheader.ascx. from user control i am hitting a search button.

    under search button_click 1. fetching data from DB and doing some validation 2. now i have to show confirm box 3.based on response from confirm box i have to continue the balance code execution in the button_click.

    i used separate method for java script like below and calling the below java script to show the confirm box.

    javaScript.Append("var userConfirmation = window.confirm('" & message & "');")
    javaScript.Append("if ( userConfirmation == true )")
    'javaScript.Append("if (<%=Page.IsPostBack%> == False) var pageId = '<%= this.UniqueID %>';
    javaScript.Append("__doPostBack('UserConfirmationPostBack', userConfirmation);")
    Page.ClientScript.RegisterStartupScript(Me.GetType(), scriptKey, javaScript.ToString(), True)

    doing the post back validation in page load.

    Page.ClientScript.GetPostBackEventReference(Me, String.Empty) 'added for Confirm message
    'If IsPostBack Then
    ' Dim eventTarget As String = If(Request("__EVENTTARGET"), String.Empty)
    ' Dim eventArgument As String = If(Request("__EVENTARGUMENT"), String.Empty)
    ' Select Case eventTarget
    ' Case "UserConfirmationPostBack"

    ' If Convert.ToBoolean(eventArgument) Then
    ' _CDBcheck = False
    ' btnSearch_Click(sender, e)
    ' Else
    ' End If
    ' End Select
    'End If

    but the issue is when i am running the application in web / IIS the confirm box is not showing. please help me to solve it very quickly

    Thursday, June 20, 2019 12:46 PM

All replies

  • User753101303 posted

    Hi,

    This is not how the web works. On the server you create an HTML/CSS/JavaScript page which is entirely created and then rendered to the client where the user will interact until the next http request.

    Depending on which kind of confirmation it is, my approach is to add that to the control right away when  clicked (for example a delete button). If cancelled nothing happens and the user can still interact with the web page. If confirmed the next postback happens and the deletion is done and an updated page or whatever is shown.

    Here it seems your approach is to let the ui element to trigger this operation, then you render a new page with a confirm box and it seems you'll try to get the response right away during the same http request ??? It is not how the web works.

    In short just ask for confirmation as soon as you can ie usually when a UI element is clicked.

    Thursday, June 20, 2019 1:10 PM