Can I use javascript to call server side function in ASP.NET

Discussion in 'ASP.NET / ASP.NET Core' started by calvin, Jan 20, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have a datagrid and allow to delete function. But before delete the record, I want to popup a message(using javascript alert message) to confirm to delete record. If user select "Yes" then, I want to call a server side function to check whether the record can be delete or not.
    So, my problem is start from calling the server side function using javascript. Is it possible to do that. If so, please give me a solution/help. Else any idea to solve the problem???
    Below is part of my code to do the delete record command:-
    Private Sub Delete(ByVal Source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
    Dim strScript As String = "<SCRIPT language='javascript'>" &amp; Environment.NewLine
    strScript = strScript + "if(confirm('Are you sure to delete?')){document.getElementById('" &amp; txtbox.ID &amp; "').value = 'Yes';***}else{document.getElementById('" &amp; txtbox.ID &amp; "').value = 'No';}" &amp; Environment.NewLine
    strScript = strScript + "</script>"
    RegisterStartupScript("focus", strScript)

    Dim strLocationID As String = e.Item.Cells(2).Text

    If txtbox.Text = "Yes" Then
    'Do a lot of coding here and call function
    Else
    ' Do nothing
    End If

    End Sub

    ***Notice the code in red color, it suppose to put inside a (serverside??)function and to be call by javascript function(notice the blue (*)marks), because it will run the code when page is rendered.

    Thank you for help and comments.
    Calvin
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page