Server side view in ASP.NET - asp.net

In my ASP.NET 5.0 project, if i add new cshtml view(from server side templates), will it mean that the Javascript and CSS etc in that view will also be executed on server instead of client's browser? Any help is appreciated.

No, only the C# razor code will be executed on the server. CSS will be rendered by the browser, and JavaScript code will also be executed by the browser. If you have code you want to run on the server, you must use razor. If you want it to run in the browser, use JavaScript. The cshtml extension simply tells the server to look for C# razor code to execute.

Related

How is an ASP.NET read by the browser?

How does the browser interpret an ASP.NET webpage, hosted in IIS?
The first time the webpage is accessed, is something installed in the browser? Or ASP.NET creates "normal" HTML pages?
IIS interprets and executes the ASP.NET code and markup and sends HTML to the browser.
The browser interprets the HTML.
ASP .NET is server side. It executes remotely and delivers standard HTML page to browser
"An ASP.NET page has the extension .aspx. If a browser requests an
ASP.NET page, the server processes any executable code in the page,
before the result is sent back to the browser."
Quoted from w3schools website.
The first time the asp.net page is accessed it is compiled into a .net class (together with the code behind). There is a so called ISAPI filter installed into iis. When you access an asp.net page (a file with .aspx extension) iis will use the ISAPI filter to execute the request using class that has been compiled.
everything you need is HERE my friend

How to browser display asp.net controls on its page when it is said it strictly understands only html content and scripts?

I m learning asp.net basics. i was going through tutorial at www.dotnetspider.com
and there it is explained browser understands only html content and scripts strictly. So when i create a webform and drop asp controls and run how does my browser understad that control content and displays on its page?
Your browser doesn't understand the ASP.NET controls. ASP.NET understands them. Whenever a web form is request ASP.NET takes the form and converts it into the HTML form and any scripts that are needed and sends them down to the browser.
Using the ASP.NET web controls makes your job easier, you don't have to worry about hooking together a bunch of HTML forms and code. But as the website says, it's all HTML to the user's browser.
Update:
When I say "ASP.NET understand them" I'm really talking about the ASP.NET frameworks and IIS (Microsoft's web server). So the request the User's browser sends out arrives at IIS. It knows from the URL that this is a request for an ASP.NET application. So it uses the ASP.NET code to take the .aspx pages and the .ascx controls and convert them into the HTML response. It then sends that HTML to the User's browser. So ASP.NET (and IIS) sit "in the middle" between the web broswer on the User's computer and the ASP.NET code and pages you write.
i just did found detail so i thought to write it might make it more clear in depth. its goes as
Browser sends request to IIS -> goes to ISAPI dll(written in C++) -> Loads CLR Process where each control have render method finally emitts its html code -> Which browser can understand and display. Please correct me if i m wrong some where.

asp.net ajax not working

I'm creating an asp.net web application.
In the web application I have a web service.
I added [System.Web.Script.Services.ScriptService]
To the web service file and added a script manager to the aspx page.
When I call the web service in javascript I get an error "Microsoft JScript runtime error: 'getText' is undefined"
This same code works in another project, but it's a website project and not a web application. Maybe there is a difference between the two in this respect?
Thank you!
-Elad
What are you trying to do with getText ? Is this a valid ASP.NET AJAX command?
Assuming it is...
Not much info to go on here, but make sure you have added a reference to the .asmx file of your service on the <ScriptManager>control in your page.
You can do this in markup, or in code like this (usually during the Page Load event):
sm.Services.Add(New ServiceReference("~/YourWebService.asmx"))
Where sm is the id of your ScriptManager.
Also, if the JavaScript file you're using to call your web service is external, load it by registering it with the ScriptManager like this rather than adding a reference to it in your markup:
sm.Scripts.Add(New ScriptReference("YourJavaScriptFile.js"))
This ensures it won't run until the ScriptManager is ready.
Also, add this line to the very end of your JavaScript file:
if (typeof (Sys) !== 'undefined') {Sys.Application.notifyScriptLoaded(); }
This notifys the ScriptManager that your JavaScript file has loaded.
I switched from a web application project to a web site project and everything started working. I don't really know why this is, but it just worked.

How to use AJAX Control Toolkit client-side functionality without IIS

I ran an ASP.NET page that i have under development on my local IIS. It uses some dragPanelExtenders as well as some other AJAX Control Toolkit AJAX client side stuff, and in order to show the page to somebody, I wanted to put it up as a plain HTML file, hosted on a live web server (running APACHE). (This is the only public web server I have access to, and I want them to be able to drag some panels and experience the page as it would be when "live")
So, I viewed the page running on my local IIS, then saved the source as a HTML file.
Then copied this HTML file to the web server ( as well as necessary CSS, JS and image files).
When I view this HTML file through the web server, I get this error :
ASP.NET Ajax client-side framework failed to load.
By debugging, I see that the following lines were in my saved HTML :
<script src="/Insata10/WebResource.axd?d=VAXZudqFsChpNfB" type="text/javascript">
<script src="/Insata10/ScriptResource.axd?d=Dwbyv-OIp-kJQdqf_UMh7wUzi2" type="text/javascript">
<script type="text/javascript">
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
So, at runtime, the referenced resources "ScriptResource.axd" and "WebResource.axd" were not found.
Is there any way to get whatever is needed from those AXD's to my HTML file, without actually executing anything on IIS?
Not easily. The Ajax Control Toolkit relies on server-side .NET Code, which runs in the context of IIS.
You can us a different web server, such as the Cassini web server that comes with Visual Studio (or write your own), but I expect that you're looking for a simpler solution, and none exist for what you're asking.
The bottom line is, the server-side code needs to run, and for that you need a server. You can't just open the file and have it work.
The best you could do would be to find similar javascript to get the desired funcitonality.
edit
I'm always forgetting about Mono, so if your Apache server is set up and configured correctly, you CAN run .NET code from an Apache server. http://www.mono-project.com/ASP.NET
Still not simple, though, so my answer of "not easily" does not change.

.ASP Do I need to compile?

I'm poking my head around ASP for work and I'm not sure how it works... I'm used to being able to create a HTML, PHP, ColdFusion page, put it on the webserver and execute it.
Do I need to compile ASP pages or is that just ASPX?
I just want to create an ASP page and put it on my web server to test...
You can just create an ASP or ASPX page and put it on the server to test. The web server in all those cases (ColdFusion, PHP, ASP, ASP.NET) takes care of compiling the page when it's accessed.
In ASP, I believe it is compiled(/interpreted) every time you load it, where as in ASP.NET it's compiled on first access (which is slow) and the compiled version is available for the next page load.

Resources