如何在不使用点击事件的情况下触发JavaScript确认框?

时间:2017-11-27 21:47:02

标签: javascript vb.net

我正在处理处理投诉的应用程序。用户无法关闭"投诉(即标记为已完成),直至满足一批条件。以前,一旦满足每一个条件,就可以“关闭投诉”#34;按钮会出现,但我已经被要求生成一个确认窗口(询问,"您准备好关闭此投诉了吗?")会在用户保存最后一个必要项目时弹出。

没问题,我想。我设置JavaScript来生成确认窗口,并在可能是关闭所需的最终项目的任何项目上添加属性到保存按钮(当满足关闭的所有其他条件时)。除了...

一旦他们点击保存记录,他们至少想要这样做,他们是否准备好关闭投诉。但目前,如果他们确认"是,"如果他们确认"否,"然后投诉没有结束,但记录都没有保存。

我在vb.net工作,使用Visual Studio 2008,我想找到的是一种在保存记录后触发确认窗口的方法(在DetailsView的ItemInserted子中)。这样,它可以获得确认并关闭或不关闭,但记录将以任何方式保存。

我能找到的每一条建议都使用按钮点击来生成JavaScript确认窗口;有人知道另一种方法吗?

编辑(添加更多背景信息):

我最初接近它的方法是制作两个相同的保存按钮。一个是保存记录的普通按钮(" ibInsert"),另一个是(" ibInsertAndClose")保存,然后关闭记录。当DetailsView在插入模式下进行数据绑定时,我会检查"准备关闭"状态,然后设置按钮的可见性。

    If ReadyToClose() Then
     Dim ibInsertAndClose As ImageButton = CType(dvResponseDetail.FindControl("ibInsertAndClose"), ImageButton)
     Dim ibInsert As ImageButton = CType(dvResponseDetail.FindControl("ibInsert"), ImageButton)
     If Not ibInsert Is Nothing AndAlso Not ibInsertAndClose Is Nothing Then
             ibInsert.Visible = False
             ibInsertAndClose.Visible = True
             ibInsertAndClose.Attributes.Add("onclick", "javascript: return confirm(""\nAre you ready to close this Complaint?"")")
     End If
    End If

1 个答案:

答案 0 :(得分:0)

如果您能够从JavaScript confirm()获得回报并且您能够保存记录,那么您可能拥有所需的一切,但您只需要有关工作流程的一些指导?

这是一些伪代码(因为我不做.NET)

function saveRecord()              'saves the record
    'database code here
end function

function closeComplaint()          'closes the complaint
    'database code here
end function

function saveButtonClick()         'call this when the save button is clicked
    saveRecord()                   'fires no matter what the response is
    dim alertConfirmedTrue = ???   'response from JavaScript confirm() function
    if alertConfirmedTrue 
       then closeComplaint()       'only called if response is "ok"
end function