Calling a ASP.NET C# function from javascript
-
Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt
-
Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt
In order to do this without a postback you really want to consider using AJAX.
-
Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt
You could probably implement the ICallbackEventHandler interface. The MSDN sample is clear enough. I tried it successfully last week. I used to write a simple page that generated random numbers on the server. I had a loop in javascript that would retrieve the latest number and update a label on the page on the client side. Here's a link to the MSDN article I used as a guide: Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages[^]