Search code examples
c#asp.netinline-code

How to write inline c# code in master page of asp.net?


I want to write inline c# code in aspx page. From googling I get that I have to add Page Language = "C#". But in master page the Language is already defined. Is there any other way to do that?

I want to add <% DateTime.Now.Year.ToString(); %> at the footer.

One way to do that is to use Literal and update it on page load. I'm looking for any other way.

enter image description here


Solution

  • You have to use the = sign at the start.

       <%= DateTime.Now.ToShortDateString() %>
    

    Which is the same as writing

    Response.Write(DateTime.Now.ToShortDateString());
    

    in the code behind.

    Yes this works on webforms.