Sudarshan Patil
Sudarshan Patil

Reputation: 1

will it be changed .aspx.cs file after converting server controls into html controls?

my question was that when I send the request to the web server, of course, the web server will take the request and give me a page that will be in the HTML format so I want to know when the web server will accept the request and of course, the request will be for .aspx page and .aspx page will be executed by the web server and all the asp server-side controls that all are on the .aspx page will be converted into HTML format so then I want to know here in the Testing. asp. cs file will be changed as well? because finally, the .aspx page will be converted into HTML you know when we get a request from an HTML tag like an HTML form tag then we need to use there like this int no1=Convert.ToInt32(Response["textbox1"]); int no2=Convert.ToInt32(Response["textbox2"]); instead of this int no1 = Convert.ToInt32(textbox1.Text); int no2 = Convert.ToInt32(textbox2.Text);

so I want to know after converting server-side controls into HTML then .aspx.cs will be changed or not these two lines will be converted into like this int no1=Convert.ToInt32(Response["textbox1"]); int no1=Convert.ToInt32(Response["textbox2"]); these two lines will be converted like this or not

file- Testing.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Testing.aspx.cs" Inherits="login.Testing" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body style="background-image:url(C:\Users\Sudarshan\source\repos\login\login\Images\uWjEogFLUTBc8mSvagdiuP.jpg)">
        <form id="form1" runat="server">
            <div>
               <table align="center">

                   <tr>
                       <td>
                           Enter the Number 1:<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
                       </td>
                   </tr>
                   
                   <tr>
                       <td>
                           Enter the Number 2:<asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
                       </td>
                   </tr>
                   
                   <tr>
                       <td>
                           <center>
                               <br />
                               <br />
                               <asp:Button ID="button1" runat ="server" Text="Add" Height="38px" OnClick="Unnamed1_Click" Width="101px" />&nbsp;</center>
                       </td>
                   </tr>
</table>
</div>
</form>
</body>
</html>

file name- Testing.aspx.cs

Request["textbox1"]
Request["textbox2"]





          

Upvotes: 1

Views: 185

Answers (1)

Albert D. Kallal
Albert D. Kallal

Reputation: 49009

our .cs file? It NEVER changes, and is compiled code. So, in fact, both the aspx page and the code behind .cs page should not under go changes. But, no reason why I can think of that the cs page behind would be changed, has to be changed, or would require to be changed. The aspx page from server is loaded, then a page class is created based on the aspx page, and then your code behind can and does operate against that class instance of the page - it does not really operate against the aspx page, but a loaded aspx page converted into a page class object. Your code runs against that class object.

So, your code behind is not really running against the aspx page. But that aspx page is converted + loaded into a page created class. It is this class object that your code behind runs against. this is kind of like loading "json" into a object when you de-serlize the json object.

So, the aspx page is really ONLY used for creating a page class object. it is this page class object that your code runs against.

So, when you go

 TextBox1.Text = "Albert"

That code is not running against or modifying the aspx page. Your code is modifying the class object that was created from that aspx page. Then the class object is converted into HTML when rendered for the client side.

So, as your code "runs" it is NOT making changes to the aspx file, it is making changes to the page class object that was created from that aspx page.

ZERO changes are made to the aspx page for this to work. The aspx page becomes your class object (the page class), and your code runs against that class with properties and methods like any C# class object has.

when you use code behind say to inject script, or even add controls to the page? You not operating against the aspx page at that point in time, but are in fact operating against the page class object - no changes EVER make their way back to the aspx page, and ZERO concept exists that your code behind is making changes to the aspx page - it NEVER does (or better said never should!!).

So, your code behind operates against the class object created from that aspx page. From that point on, your code is making changes to the class object, and does not care or modify the original aspx page. As a general rule, that original page is never changed or touched at all (once it been loaded and converted to that page class object).

So no changes have to occur to your c# code, but that code NEVER operates against the aspx page, but ONLY every operates against the page class object that was created for you from the aspx page. Your c# code runs BEFORE any conversion of the page class to standard HTML which is then sent to the client.

Upvotes: 1

Related Questions