编辑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.csfile open or know its path, head to the Solution Explorer. Usually, the.ascxfile lives right alongside its code-behind (either in the same directory, or you can expand theascx.csnode to reveal it). Just double-click the.ascxfile to open it. - If you can't spot it right away, check the top of your
ascx.csfile for the partial class name (e.g.,public partial class UserProfileControl : System.Web.UI.UserControl). PressCtrl+Shift+Fin Visual Studio, search for that class name, and look for the.ascxfile—its directive will look like this:
That's your matching ASCX file.<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserProfileControl.ascx.cs" Inherits="UserProfileControl" %>
2. Find All Pages/Controls That Reference This ASCX
- Use Visual Studio's built-in reference search: Right-click the
ascx.csor.ascxfile 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 theTagNameor theSrcpath usingCtrl+Shift+Fto 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 thetagPrefixandtagNamecombo 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
相关产品推荐
相关产品推荐

