C# .NET - Calling a c# method from javascript on condition of confirm "true"
Asked By karur krishna madhu on 11-Oct-13 08:20 AM
I have to call a c# function from javascript
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "visitid", "Visitidfn()", true);
function Visitidfn()
{
if(confirm("Populate Customer fields with existing Visit Request Form entries.Continue?"))
{
return true;//here i used _dopostback but it didnt work ..
}
else
{
return false;
}
}
after this confirm is shown on browser i need to call
Pullvisitinfo();
loadRequest(int.Parse(txtvisit_id.Text));
c# functions if user clicks on ok in the confirm box.
Robbe Morris replied to karur krishna madhu on 10-Oct-13 02:41 PM
JavaScript is client side. C# is server side. HTTP is a disconnected protocol. In order to perform what you are after, JavaScript has to make an http request to the server. Either through postback or some sort of http request call. I would suggest using ASP.NET Page Methods if you are in a newer version of ASP.NET.
https://www.nullskull.com/a/1673/more-aspnet-pagemethods-with-jquery-and-json.aspx