Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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'>" & Environment.NewLine

strScript = strScript + "if(confirm('Are you sure to delete?')){document.getElementById('" & txtbox.ID & "').value = 'Yes';***}else{document.getElementById('" & txtbox.ID & "').value = 'No';}" & 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...