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
karur krishna madhu replied to Robbe Morris on 22-Oct-13 05:30 AM
thanks morris 
I am able to find a work around for that i created a button in the UI made it invisible and then in that button click event i kept the c# functionality to be called and invoked this button click in js using document.getelmentby id(btn).click();