You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编辑ASP.NET的ascx.cs后,如何在VS2017中打开页面及查找引用

How to Locate Your Edited ASCX File & Its References

Got it, let's work through this for you:

1. Open the Corresponding ASCX Page

  • If you already have the ascx.cs file open or know its path, head to the Solution Explorer. Usually, the .ascx file lives right alongside its code-behind (either in the same directory, or you can expand the ascx.cs node to reveal it). Just double-click the .ascx file to open it.
  • If you can't spot it right away, check the top of your ascx.cs file for the partial class name (e.g., public partial class UserProfileControl : System.Web.UI.UserControl). Press Ctrl+Shift+F in Visual Studio, search for that class name, and look for the .ascx file—its directive will look like this:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserProfileControl.ascx.cs" Inherits="UserProfileControl" %>
    
    That's your matching ASCX file.

2. Find All Pages/Controls That Reference This ASCX

  • Use Visual Studio's built-in reference search: Right-click the ascx.cs or .ascx file in Solution Explorer, then select Find All References. This will populate the Find Results window with every place the control is used—whether in ASPX pages, other ASCX controls, or even global registrations.
  • Search for registration tags: If your control is registered per-page (like <%@ Register TagPrefix="myUC" TagName="UserProfile" Src="~/Controls/UserProfileControl.ascx" %>), search for either the TagName or the Src path using Ctrl+Shift+F to find all instances where the control is declared (e.g., <myUC:UserProfile runat="server" ID="UserProfile1" />).
  • Check global registrations: If the control is registered in your web.config (under <pages><controls>), search for the tagPrefix and tagName combo across your solution—any use of that prefix/name pair is a reference to your control.

Quick Tip to Verify Usage

If your breakpoint isn't hitting, you can add a quick debug line in the Page_Load method of your ascx.cs file:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("This control loaded successfully!");
    // Rest of your code...
}

Run the app and check if that text appears on the page—if not, the control isn't actually being loaded by the page you're testing, which confirms you're looking at the wrong control.

内容的提问来源于stack exchange,提问作者user3652172

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:13:26