The requested page is not available for the requested platform. You are viewing the content for Default platform.

Move to Code-behind (ASP.NET)

  • 2 min read

Moves code located in <script> tags to the code-behind file.

Purpose

If parts of server code are located in ASPX pages, it is harder for you to locate the desired code fragments. To make code maintenance easier, you can move all server code to code-behind files.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on a <script> tag.

Notes

  • Move to Code-behind (ASP.NET) moves all code from the <script> tag to the code-behind file. The <script> tag is automatically deleted.
  • The target picker allows you to choose the location for the extracted code.

Example

// .cs file

using System;
using System.Web.UI.WebControls;

public partial class MoveToCodeBehind : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

Result:

// .cs file

using System;
using System.Web.UI.WebControls;

public partial class MoveToCodeBehind : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        Button MyBtn = (Button)sender;
        MyBtn.Enabled = false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Animation

rsMoveToCodeBehind