Results 1 to 3 of 3

Thread: [02/03] Msgbox sequence problem, thanks for help :-)

  1. #1
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 07
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    [02/03] Msgbox sequence problem, thanks for help :-)

    Hi all,

    I'm newbie of ASP.net , I had create a datagrid which enabled user edit record within the datagrid. Before the user update the record into the database the page will calling a confirm messagebox from msgbox.dll to get confirmation from user. If the user click on OK then the update statement will be proceed and prompt a message to indicate update completed.

    But now my issue is the sequence of messagebox is wrong in which it will execute the update statement. Afterward, the confirm alert messagebox.

    Anyone know the reason or solution?

    I posted my code behind.


    ASP Code:
    1. Private Sub dgSchoolName_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgSchoolName.UpdateCommand
    2.         Dim myds As New DataSet
    3.         Dim myDT As New DataTable
    4.         Dim mydr As DataRow
    5.         Dim strsql As String, strUpdateSqL(0) As String
    6.         Dim dgTxtSchoolName As TextBox = CType(e.Item.Cells(2).FindControl("txtSchoolName"), TextBox)
    7.         Dim dgSchoolNo As String = Convert.ToString(e.Item.Cells(1).Text)
    8.         Dim getSchoolName As String = dgTxtSchoolName.Text
    9.         strsql = "SELECT SchoolName From SchoolName WHERE SchoolNo = '" & dgSchoolNo & "'"
    10.         Try
    11.             MsgBox2.confirm("Do you want to update for School No " + e.Item.Cells(1).Text + " ?", "Confirmation")
    12.             If (IsPostBack) Then
    13.                 If Request.Form("Confirmation") = 1 Then
    14.                     Request.Form("Confirmation").Replace("1", "0")
    15.                 End If
    16.             End If
    17.  
    18.             myds = myC.GetRecordSet(strsql, "Greenwave", "SchoolName", "GreenWave.xml")
    19.             myDT = myds.Tables("SchoolName")
    20.  
    21.             If myDT.Rows.Count = 0 Then
    22.                 MsgBox1.alert("Record Not Found, Update Failed")
    23.                 Me.dgSchoolName.EditItemIndex = -1
    24.                 Exit Sub
    25.             Else
    26.                 If dgTxtSchoolName.Text = vbNullString Then
    27.                     MsgBox1.alert("School Name cannot be blank")
    28.                     Exit Sub
    29.                 Else
    30.                     strUpdateSqL(0) = "UPDATE SchoolName" & _
    31.                                    " SET SchoolName = '" & getSchoolName & "'" & _
    32.                                    " WHERE SchoolNo = '" & dgSchoolNo & "'"
    33.  
    34.                     If (myC.Ins_Update_DeleteRecord(strUpdateSqL, "Greenwave", "GreenWave.xml")) = True Then
    35.                         MsgBox1.alert("Update Completed")
    36.                     Else
    37.                         MsgBox1.alert("Failed to Update")
    38.                     End If
    39.                 End If
    40.             End If
    41.             Me.dgSchoolName.EditItemIndex = -1
    42.             dgSchoolName.DataBind()
    43.         Catch ex As Exception
    44.         End Try
    45.  
    46.     End Sub
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 07
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [02/03] Msgbox sequence problem, thanks for help :-)

    Your help would be greatly appreciated.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  3. #3
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: [02/03] Msgbox sequence problem, thanks for help :-)

    I'm not sure if you're aware of the difference between client side and server side scripting. You cannot perform a javascript prompt from the codebehind after a postback occurs. When a postback occurs, the entire sequence of code will be executed and then the output is sent back to the browser. You will need to add an onclick attribute to your existing buttons. Something like this

    onclick="return confirm('Are you sure?');"

    This will determine whether the postback actually occurs or not, saving you the roundtrip.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •