Click here to Skip to main content
Sign Up to vote bad
good
Hey,
 
I'm new to the ASP .NET technology (but much acquainted to other .NET technologies like C#). I would like to know whether (and how) is it possible to execute C# code simply when the page loads, given all the relevant data from the HTTP request (pass POST information to it). and simply write the returned string back in the HTTP response.
 
Thanks a lot for helping.
Posted 13-Oct-12 2:45am

Comments
n.podbielski - 13-Oct-12 8:51am
On server side or client side? Do you mean like web page will load in browser? Then you want to run some server code?
ShacharK - 13-Oct-12 9:04am
I would like to write minimal amount of ASP code. I have no real need for any web features provided by the HTTP protocol. I use the http server as a platform to have clients communicating with my database using my custom JSON-based protocol. You send a request, My protocol which I want to implement in C# processes information, makes the desired API Calls, and prints out a simple JSON-object response (instead of an actual website's html)
thewazz - 13-Oct-12 10:18am
this help? http://social.msdn.microsoft.com/search/en-us?query=request
n.podbielski - 13-Oct-12 14:35pm
Then why wont you just use JSON enabled WCF service?
ShacharK - 14-Oct-12 16:12pm
Would that be better? Isn't WCF an overkill? I always found this technology far too complicated for any of my needs in the past. I would love to hear your opinion.
n.podbielski - 15-Oct-12 1:11am
It is complicated if you want to run it exactly as you want. But you can also click-add-create it in vs. Ide will do everything for you. With json it is more demanding depending of how you want to call this service. If from .net site you can just add service reference from vs. If from example jQuery it is more complicated. Last time i was creating service i spend few hours just for configuring from which url this will be executed :) Write from where you would want to call this solution. Again wcf is complicated but also very powerful. So i think this wil be less error prone then your custom solution. For starter you have many things out of the box (authorization, serialization, deserialization, asp.net js scripts, data validation etc.) which in your solution you will have to make yourself. Yes you can also just add asp.net app to your iss. Delete html from default.aspx and in page load deserialize some parameter to object calculate something and return another object serialized as JSON with Response.Write It will be simple and it will work after 1 hour so again it depends what you want. But if it will have to be more complicated i would add WCF service just to learn how to do that. Its popular technology so experience with it will not hurt.

1 solution

Hi,
The simple approach: in Page_Load event (pertinent to ASP.NET server side) use !IsPostBack property that indicates the first page load.
 
Read more on this topic here: http://stackoverflow.com/questions/5364375/page-load-vs-onload[^]
 
Regards,
AB
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 477
1 Ron Beyer 316
2 samadhan_kshirsagar 269
3 Tadit Dash 243
4 OriginalGriff 181
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,370
4 CPallini 3,034


Advertise | Privacy | Mobile
Web01 | 2.6.130619.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid