Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Ok i have a button on my page that when clicked on i need it to delete a row from a table in SQL Developer.

MY button is created with a table server side with an on click event..
VB
bt2 = New HtmlGenericControl("div")
                bt2.InnerHtml = "<input type=button onclick=deleteUser('" & dt.Item("login_id").ToString & "') value='Delete User'>"


I need help with writing a javascript function for it that when pressed an alert with come up asking are you sure you want to delete and if yes the user is deleted and if no the message disappears.

i have this function but i am unsure of what i need to write server side to make the button delete from database.

C#
function deleteUser(delUserid) {

        if (confirm("Are you sure you want to delete? This action cannot be undone.")){

            var link = 'DeleteUser.aspx?userid' + delUserid

            $.get(link, function (data) {

            });

        }

        else{ return false;
        }


       
    }



I have tried this server side but doesnt seem to work

VB
If Request.QueryString("userid") <> "" Then

           Dim delResult As dataset
           Dim dt As DataTableReader

           delResult = GetUserName.deleteUser(Request.QueryString("userid").ToString)
           dt = delResult.CreateDataReader


       End If




Thank you
Posted
Updated 20-Jan-15 4:08am
v5
Comments
Kschuler 20-Jan-15 16:47pm    
Where is your server side code being called from? The button's click event? Can you provide us with more information on what GetUserName.deleteUser does? What do you mean when you say it doesn't work? Does it error out? If so, what is the error message and where do you get it? Or does it just not delete the record you want it to?
Member 11355710 21-Jan-15 3:42am    
Thank you for your reply, i apologize i did not give very good information within my question i will make sure i do when i ask another. I have found a solution to my problem so i will add this to question.

1 solution

I managed to find a solution to my problem.

Basically the button would poop up with an alert stating are you sure you want to delete but nothing would happen if i pressed i am sure.

What i was missing was a link between the function for the delete button and the sql function to delete the user.

I had to create another page to add the server side code that links the button to the SQL

code added to new page..

VB
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    If Request.QueryString("userid") <> "" Then

        Dim delResult As New DataSet
        Dim dt As DataTableReader

        delResult = GetUserName.deleteUser(Request.QueryString("userid").ToString)
        dt = delResult.CreateDataReader



    End If


End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900