call js confirm from code behind

落爺英雄遲暮 提交于 2019-12-14 02:36:14

问题


codebehind

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim ResourceObject As Object


        Dim js As [String] = (vbCr & vbLf & " if(confirm('Esta Seguro de eliminar de la lista')==true)" & vbCr & vbLf & " document.getElementById('" & txtRespuesta.ClientID & "').value='true';" & vbCr & vbLf & " else" & vbCr & vbLf & "  document.getElementById('") + txtRespuesta.ClientID & "').value='false';" & vbCr & vbLf & " "
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Key", js, True)

  If txtRespuesta.Text = "true" Then
         -Action 1
  Else
             -Action 2
  End If

   End Sub

Designer

 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

<tr >
        <td  align="center" colspan="2">
          <asp:TextBox ID="txtRespuesta" runat="server" Width="174px" Height="21px"  
                MaxLength="20" style="font-weight: 700"  Font-Names="Verdana" TabIndex="2"></asp:TextBox>   
        </td>
    </tr> 
 <asp:Button ID="btnUpdate" runat="server"   Height="28px" 
                style="font-weight: 700" Text="変更" Width="68px" TabIndex="3" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="btnDelete" runat="server" 
  </script>
        </ContentTemplate>
    </asp:UpdatePanel>

Please help. ScriptManager.RegisterStartupScript does nothing.


回答1:


Are you expecting an immediate confirm-popup so your next line (If txtRespuesta.Text = False Then) can react to it?

That will not happen! Only when the processing of the code-behind is completed, then something is sent to the browser. So only then can a confirm pop up. And the next postback could react to the changed value.



来源:https://stackoverflow.com/questions/1491210/call-js-confirm-from-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!