We help IT Professionals succeed at work.
Get Started

Webmatrix and confirmation message

panJames asked
Last Modified: 2012-05-12
Hello experts.

I am creating new website using webmatrix.

I want to display confirmation message before user decides to really delete something.

How can I do it?

Please have a look at the code attached.

thank you

This is how I fetch data:

var db = Database.Open("StarterSite");
var itemsSelected = db.Query("select * from Items where UserFK = @0", @WebSecurity.CurrentUserId).ToList();

This is how I display data:

@foreach (var p in itemsSelected) 
	<input type="button" value="Delete!" onclick="itemDelete(@p.id)" />

itemDelete is actually a javaScript function:

function itemDelete(index)
	var r=confirm("Are you sure?");
	if (r==true)
			//this is actually a c# code where I cannot use "index" variable
			var db = Database.Open("StarterSite");
			db.Query("DELETE FROM Items WHERE id = @0", index);

//so I can either:
//learn how to get access to java script variables for my c# code
//or learn how to generate a "are you sure?" form using c#

//additional questions:
//how can I create c# methods to be used within WebMatrix?
//how can I attach them to buttons- like "onclick" in my example?

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE