简体   繁体   English

Visual Studio HTML源模式下的C#命名空间/类别名

[英]C# Namespace/class alias in Visual Studio Html Source mode

Is there any way to create a Namespace alias in a .aspx file (not code-behind .aspx.cs). 有什么方法可以在.aspx文件中创建命名空间别名(不在.aspx.cs背后的代码中)。

For example... in a code-behind file an alias can be created as follows: 例如,在代码隐藏文件中,可以按以下方式创建别名:

using MyPanel = System.Web.UI.WebControls.Panel;

In html source mode (Visual Studio) a Namespace can be imported as follows: 在html源模式(Visual Studio)中,可以按以下方式导入名称空间:

<%@ Import Namespace="System.Web.UI.WebControls" %>

What I need to do is something like the following: 我需要做的是如下所示:

<%@ Import Namespace="MyPanel = System.Web.UI.WebControls.Panel" %>

EDIT/UPDATE: Obviously that does not work. 编辑/更新: 显然这不起作用。 Is it possible some other way without using code-behind? 是否可以通过其他方式而不使用后台代码? Yes, it actually does work if you remove the whitespace (hat tip @Alex below). 是的,如果您删除空格,它确实可以工作(下面的帽子提示@Alex)。 Example: 例:

<%@ Import Namespace="MyPanel=System.Web.UI.WebControls.Panel" %>

Actually, your third example does work. 实际上,您的第三个示例确实有效。 You need to get rid of the white space. 您需要摆脱空白。 To get your ASPX namespace alias working, write the namespace declaration like this: 要使您的ASPX名称空间别名正常工作,请编写如下名称空间声明:

 <%@ Import Namespace="MyPanel=System.Web.UI.WebControls.Panel" %> 

One contol is blocking another control:theetat When I am trying to run my codedUITest to set some text in my edit box I get the following error: 一个控制阻止另一个控件:theetat当我尝试运行自己的codedUITest在编辑框中设置一些文本时,出现以下错误:

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnBlockedControlException: Another control is blocking the control. Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnBlockedControlException:另一个控件正在阻止该控件。 Please make the blocked control visible and retry the action. 请使被阻止的控件可见,然后重试该操作。 I have had this issue before and I have been able to work around it by clicking on the center of the text box like so: 我以前遇到过此问题,可以通过单击文本框的中心来解决此问题,如下所示:

Mouse.Click(new System.Drawing.Point(sentControl.BoundingRectangle.Width / 2 + sentControl.BoundingRectangle.X, sentControl.BoundingRectangle.Height / 2 + sentControl.BoundingRectangle.Y)); Mouse.Click(新System.Drawing.Point(sentControl.BoundingRectangle.Width / 2 + sendControl.BoundingRectangle.X,sentControl.BoundingRectangle.Height / 2 + sentControl.BoundingRectangle.Y));

Where "sentControl" is the control that you want to click. 其中“ sentControl”是您要单击的控件。 Then do a SendKeys("mystuff") to the window as a whole. 然后对整个窗口执行一个SendKeys(“ mystuff”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM