views:

416

answers:

1
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 = False Then
         -Action 1
  Else
             -Action 2
  End If

   End Sub



<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" />
                  <asp:Button ID="btnDelete" runat="server" 
  </script>
        </ContentTemplate>
    </asp:UpdatePanel>

calling js from code behind not working

A: 

No, you can't call Javascript code directly from code behind. There is no direct connection between the page currently shown in the browser and the code behind.

The page that is created by the code behind doesn't exist yet, it will exist after the code behind has completed, sent the HTML code to the browser, the browser has parsed it, and displayed it as a new page.

The script that you add to the page will run once the page is sent to the browser, but you expect it to run immediately, but that doesn't happen.

Also, you expect the Javascript code to change the value of a textbox and that value to immediately be visible in the server control. For that to be possible, the value had to be sent back in time before the current request was sent to the browser, so that the value is read into the control when it's created.

You should have your confirm code already on the page, so that you can run it in the browser before the page is posted back to the server. Once the postback is sent, it's too late to do anything in the browser until the request is completed and the new page is loaded in the browser.

Guffa
Thank you.Any other workaround to get this thing done.
rockrule
Im using ajax confirm button extender.This solves my problem.Thank you for ur valuable comment.
rockrule