Click here to Skip to main content
16,019,140 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Any one have an idea on Confirm Dialog in Asp.net C# .

Note: C# Code Behind

if Confirm=="Yes" Then

Block A Should execute

else

Block B Should excute

What I have tried:

I tried with RegisterStartupScript in Code Behind but it shows only at the end of execution.I tried with Javascript but it fires on Client side  
Posted
Updated 9-Jun-17 0:23am

You can't do that in a web site: you have to use Javascript and HTML objects to interact with the user, you don't try and get an immediate response in C# before continuing.

See here: Javascript confirm from code behind using C# | The ASP.NET Forums[^] - it shows one way to do it.
 
Share this answer
 
Comments
Sivachandran R 9-Jun-17 6:31am    
Thanks For your Reply. My project is a Content management where control are created dynamically. So to apply with Javascript and HTML Object looks difficult
 
Share this answer
 
Comments
Sivachandran R 9-Jun-17 6:33am    
hi i have used this one in MVC but when i try to use this in ASP.net C# it shows me 403 Server error.I want to confirm that whether it works in Asp.net C#


$.ajax({
type: "POST",
url: "BLL.cs/METHOD?PTR=" + String(texts),
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",

success: function (msg) {
if (msg.d == true) {
alert("ok");
return true;
}
else {
var mob = '<%= Session["str_mob"] %>';
var name = '<%= Session["str_fname"] %>';
if (confirm("Mobil Number Already Exist in " + mob + " from " + name + "Press Ok To Continue") == true) {
return true;
}
else {
return false;

}
}
}
});
F-ES Sitecore 9-Jun-17 7:10am    
You can't call code like that, a .cs file is simply something your compiler uses to generate code, it doesn't (shouldn't) exist on the server and if it does it is just a text file. You'll need to create a WebMethod and you can call the web method using ajax. Google "asp.net c# call webmethod from jquery" and you'll find examples.

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