Doubt c # javascript

0

So far to do a login using a database to verify it, what it did was that with javascript validate the form information, to then send the data, which through php, to a query to the database, which will corroborate the data entered by the user, with those stored in the database.

But now using ASP , I created a login using the toolbox that creates objects <asp:button> and elements of this style with c# , then I created the connection to the database, to pick up the answer from the query to the database, and finally, I verified that the data in the database were the same as those entered by the user in the login.

The code I used is something similar to this:

Usuario usu1=new Usuario();

//el email y el password serian los 2 textbox que he creado para que el cliente introduzca los datos
if (usu1.Login==this.Email.Text&&usu1.Password==this.Password.Text){

    //y ahora el codigo que nos llevaria  a la pagina web de los usuarios correctos
}

And my question is:

When using ASP I did not need to use javascript for anything, since I did everything with c# . This would be well done ?, since it works correctly and if it is well done as it is that I do not need to use javascript ?

Since I understand that javascript is to program in the client and c# would be a language to program in the server.

    
asked by wuasaa 15.12.2016 в 01:04
source

4 answers

2

The controls of asp.net maryoria run on the server side, that's why you do not need javascript , and in asp you have two files the .aspx and the .cs , the aspx has the HTML code and the .cs have the code behind.

Annex text of the following link:

Tutorial ASP.NET: Using code behind the model or online code

  

Our example will have two files:

     
  • Default.aspx
  •   
  • Default.cs
  •   

    Default.aspx: It will include everything related to the user interface.

         

    Default.cs: Here we will put the code of the events that are executed   from the form.

    As indicated by the previous explanation, in asp.net the file .aspx is only the user interface and the file .cs which is in c# is where the events of the interface are programmed, more similar to the programming for windows . In the case of PHP and other languages there is no code behind maybe that's why it seems illogical.

        
    answered by 15.12.2016 / 01:11
    source
    1

    You do not need JavaScript, being strict you would not need PHP either, the data of the 'form' is sent automatically with an 'input' type 'submit', you only need JavaScript if you want to make your call to the server with AJAX. Now ASP.NET generates enough JavaScript code to lighten the production time (although sometimes the execution time is affected), for example it can generate code to make asynchronous calls.

        
    answered by 15.12.2016 в 01:29
    1

    What you can do with javascript on the client side can be done with C # on the server side and gives the same results, only that there are situations in which making simple queries to the server is not feasible because this can cause slowness making so many calls to the server, take into account that in a server there are thousands and thousands of queries every second.

    For validations use javascript or you can use the validator that you already have asp.net, search them in the toolbar.

        
    answered by 15.12.2016 в 05:21
    0

    > > > When using ASP, I did not need to use javascript at all, since I did everything with c #. Would this be well done?

    What I can not visualize in the code you have implemented is at what point do you access the db to validate the username and password

    Alli only instances a user class and you define an if, with that alone it is not enough to validate against a db, you need to use ado.net

    Beyond this point the rest is correct

    > > since it works correctly for me and is it well done, why do not I need to use javascript?

    You do not need javascript because you make a submit to the server using the events of the asp.net controls

    It would be different if you want to implement this without refreshing the form, in that case you should use javascript with jquery and invoke a WebMethod on the server side, in this case the events would not apply, unless you use the UpdatePanel control

    Note: in php it is not mandatory to use javascript to implement what you plan

        
    answered by 15.12.2016 в 01:39