server run at the server RRS feed

  • Question

  • User-1442981517 posted

    Please see this program

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR
    <script runat="server">
    protected void TimeLabel_Load(object sender, EventArgs e)
     TimeLabel.Text = DateTime.Now.ToString();
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <title>Single-File Web Form</title>
     <form id="form1" runat="server">
     The time is:
     <asp:Label ID="TimeLabel" runat="server" onload="TimeLabel_Load"></asp:Label>
    //the script and the form are processed inn the server we 
    //know this 
    // then why does head part is also given to run at the server


    Sunday, December 14, 2014 8:42 AM


  • User281315223 posted

    Setting the runat="server" attribute on any particular elements simply allows you to perform server-side operations on them and access them from your code-behind. It doesn't necessarily mean that it is going to be entirely run at the server and shouldn't be required in most cases.

    For example, if you were to add an ID attribute to your <head> element, you would be able to access it from your code-behind (or server-side code) using something like :

    <head id="HeadContent" runat="server">
     <title>Single-File Web Form</title>

    This would allow you to use "HeadContent" within your code-behind and perform any specific operations that you needed to do on it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 14, 2014 9:11 AM