panJames
asked on
Webmatrix and confirmation message
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
panJames
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
panJames
*****************************
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);
}
}
else
{
}
}
//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?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Tried such a trick:
function deletion(a)
{
var r=confirm("U sure?");
if (r==true)
{
hdnbox.value = a;
@{
var db = Database.Open("StarterSite ");
var index = Request.Form["hdnbox"];
db.Query("DELETE FROM Items WHERE id = @0", index);
}
}
}
<input type="hidden" id="hdnbox" name="hdnbox" value="0"></input>
but get error message:
System.ArgumentNullExcepti on: Parameterized query expects a parameter value which was not supplied.
panJames
function deletion(a)
{
var r=confirm("U sure?");
if (r==true)
{
hdnbox.value = a;
@{
var db = Database.Open("StarterSite
var index = Request.Form["hdnbox"];
db.Query("DELETE FROM Items WHERE id = @0", index);
}
}
}
<input type="hidden" id="hdnbox" name="hdnbox" value="0"></input>
but get error message:
System.ArgumentNullExcepti
panJames
Hi,
Fir this scenario you have write all deletion process in C# not in javascript, then you have full control on all the functionality of deletion process and you can do any you want.
Regards
Dani
Fir this scenario you have write all deletion process in C# not in javascript, then you have full control on all the functionality of deletion process and you can do any you want.
Regards
Dani
ASKER
Dani:
Is "function deletion(a)" a correct C# declaration of a method?
It does not compile.
panJames
Is "function deletion(a)" a correct C# declaration of a method?
It does not compile.
panJames
Hi,
Check out the following link
http://www.csharp-station.com/Tutorials/Lesson05.aspx
http://www.codeguru.com/Csharp/Csharp/cs_syntax/anandctutorials/article.php/c5829
Check out the following link
http://www.csharp-station.com/Tutorials/Lesson05.aspx
http://www.codeguru.com/Csharp/Csharp/cs_syntax/anandctutorials/article.php/c5829
ASKER
Dani: these links do not solve my problem.
I have really one problem here:
function delete(index)
{
var r=confirm("Are you sure?");
if (r==true)
{
@{
var db = Database.Open("StarterSite ");
//######################## ########## #####
//HOW CAN I GET VALUE OF "INDEX" HERE???
//######################## ########## #####
db.Query("DELETE FROM table WHERE id = @0", index);
}
}
}
thank you
panJames
I have really one problem here:
function delete(index)
{
var r=confirm("Are you sure?");
if (r==true)
{
@{
var db = Database.Open("StarterSite
//########################
//HOW CAN I GET VALUE OF "INDEX" HERE???
//########################
db.Query("DELETE FROM table WHERE id = @0", index);
}
}
}
thank you
panJames
Hi,
If the above function with delete query work then the index variable contains required.
Please checkout.
Dani
If the above function with delete query work then the index variable contains required.
Please checkout.
Dani
ASKER
Dani: can you re- phrase your sentence please?
I do not understand it.
index variable is not being seen because it is inside c# code, outside of JS scope.
panJames
I do not understand it.
index variable is not being seen because it is inside c# code, outside of JS scope.
panJames
db.Query("DELETE FROM table WHERE id = @0", index);
in above line i am talking about index if above line works fine then you can use index variable
in above line i am talking about index if above line works fine then you can use index variable
ASKER
But I cannot use index variable as explained above.
panJames
panJames
ASKER
My deletion code needs to know the index of a row to be deleted.
So I need to pass this variable to javaScript (I know how to do it) but use it in c# code (which I struggle with).
panJames