Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is C# using any Scripting language for Events?

Tags:

c#

asp.net

c#-4.0

One of my friend (a php developer) told me that C# doesn't have the capacity for managing events, means events are not generated or not controlled by C# codes (Like Button Click, Selected Index Changing etc). Its by some other scripting language like JavaScript and he told me its JScript. And that all the controls like labels, buttons are client side and doesn't need to go in to server.

Then my question is Why runat="server" for all asp controls? He also told that redirection (Response.Redirect) is also happening in client side, its not server side and C# don't have the ability to do so because its a PROGRAMMING LANGUAGE not a SCRIPTING LANGUAGE.

I am totally confused with his Answer and I am not satisfied with his answer. Can some one tell me what it is?

  1. What is runat="server"? And what if all controls are client side?
  2. Does c# have the ability to Redirect, Event Generation, handling etc?
  3. If c# doesn't have the ability then which scripting language is windows using? And how it works independent to browser?
  4. What about Response.Redirect? Is it client side ? Then how it works?
  5. Does ASP using any Scripting language for events ?

I am new to C#. May be this is poor question but can someone give proper answer? I am totally confused.

By events means, Events like Button_Click,SelectedIndexChanged etc
And i mentioned C# here because i am using C# ,
Thank you

like image 999
Arun CM Avatar asked Jan 27 '14 06:01

Arun CM


People also ask

Is C+ Same as C?

C++ was developed by Bjarne Stroustrup in 1979. C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming. C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language. C is (mostly) a subset of C++.

What is C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What does %c mean in C?

%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.

Is C still used in 2022?

C is one of the earliest and most widely used programming languages. C is the fourth most popular programming language in the world as of January 2022. Modern languages such as Go, Swift, Scala, and Python are not as popular as C.


2 Answers

It's not a language thing, it's a framework/technology thing. For example, ASP.net web forms can handle events in the code behind similar to how you would in a windows application, but it's really just wrapping http requests. In MVC (which is also C#), you deal with page "events" by interacting with the controller using your standard http verbs (get, post, put, delete, etc).

I'd tell him that php doesn't handle events either in that case. Since both php and asp are server side languages, they all respond to http requests, not events. But clicks tell the browser to do stuff and communicate with the server. javascript would handle events and then communciate with the server, but the point is, his argument is a bit mixed up.

Other answers:

  1. Runat server just tells asp that you want to use this object on the server, so it creates some objects and references to html elements so that you can interact with them in the server side code.
  2. Yes
  3. Windows isn't using a scripting language. Your asp application is using whichever language you programmed it in. However, ASP.net does generate some javascript in order to emulate windows desktop programming styles.
  4. Response.Redirect happens on the server side, it just tells the framework to build an object that will translate to a proper HTTP response.

You might want to study up on some of the basics of web development. Specifically how http is statless and how http verbs work. It's easier to understand what the framework is doing when you understand what is happening when you're NOT using a framework.

UPDATE: After the edits, I re-read your post and I see what the issue is. Your friend is mostly right. C# isn't a client side language, so it can't react to page events -- so he's correct there. However, what ASP.net does is generate javascript that bridges this gap. Conversely, ASP/MVC doesn't do this, so you'd have to write the javascript (or even just basic form submissions) that would talk to the controller, and then you would have to handle the server response accordingly.

So he is right, you can't directly write C# code to respond to page events. But if you develop in C# using ASP.net, it will allow you to code in C# and generate the necessary javascript for you. It'll be mostly seamless from your point of view.

like image 185
Sinaesthetic Avatar answered Sep 28 '22 08:09

Sinaesthetic


I think perhaps the context of the conversation you had with you friend needs to be understood. It seems you are referring to ASP.net not necessary C# in general.

1. What is runat server And why if all controls are client side

What needs to be understood in the ASP.net world is the difference between design time, server side and client side. In the basic life cycle of a page the compiler would use the design time pages to understand how to construct a control tree on the server side. Controls marked as runat="server" tell the compiler that the control as part of the design needs to form part of the control tree that will get constructed on the server.

2.Is c# have the ability to Redirect,Event Generation,handling etc

Context is important here I suspect we are not talking about C# in general rather ASP.net? ASP.net uses events as the way to interact with requests from the server. When you click on a typical page in ASP.net the client side javascript hooks will catch the onlick event and construct the request to send to the server. The Page will then post back the viewstate, event and event arguments to server. The server side will reconstruct the control tree from the viewstate and based on the event and event arguments raise the appropriate event on the server. If you have setup the server side hooks for the event you will catch them as you would any event. Redirect wouldl also be something that happens in server side code.

3. If c# dont have the ability then which scripting language is windows using ? and how it works independent to browser

C# is not a scripting language it is compiled, well... for the sake of brevity we go with it's compiled. ASP.net pages typically is the combination of both C# server side code and client side javascript code. Cient side would catch events and pass the request onto server side.

4.and What about respose.redirect ? is it client side ? then how it works

Response.redirect would be server side not client side. If you need to redirect to a page client side you would use javascript window.location.href = '...'; or something similiar

like image 45
Warrenn enslin Avatar answered Sep 28 '22 10:09

Warrenn enslin