Search code examples
asp.netvariablescode-behindassign

Are there any difference between aspx and code behind when assigning text values asp.net 4.0 c#


This is code behind assigning aspx.cs

      if (srLang == "tr")
    {
        lblUnWantedPrivateMessages.Text = "Özel Mesaj Almak İstemediğiniz Oyuncular";
        lblPmBlockUserNameTitle.Text = "Oyuncu Adı:";
    }
    else
    {
        lblUnWantedPrivateMessages.Text = "Players That You Don't Want To Receive PM";
        lblPmBlockUserNameTitle.Text = "Player Name:";
    }

and this is aspx assigning

    <%    
    if (srLang == "tr")
    {
        lblUnWantedPrivateMessages.Text = "Özel Mesaj Almak İstemediğiniz Oyuncular";
        lblPmBlockUserNameTitle.Text = "Oyuncu Adı:";
    }
    else
    {
        lblUnWantedPrivateMessages.Text = "Players That You Don't Want To Receive PM";
        lblPmBlockUserNameTitle.Text = "Player Name:";
    }
     %>

Are there any performance difference between these 2 ?


Solution

  • Both will compile into equivalent code, and there will be no performance difference.

    Placing significant code in the code behind file allows for a separation of responsibilities (display markup in the aspx file, logic in the code behind file) and leads to code that is easier to maintain.