Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Web-Development , +
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 at 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 at 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 at 13-Oct-12 10:18am
   
this help? http://social.msdn.microsoft.com/search/en-us?query=request
n.podbielski at 13-Oct-12 14:35pm
   
Then why wont you just use JSON enabled WCF service?
ShacharK at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100