虚假(但严重)“[WebElementId] 未声明” VB.NET 中的错误
因此,当我尝试通过文件菜单构建网站时,出现标题中提到的错误。导致这种情况的代码如下(出现在 body 标记中的 JavaScript):
if(editedRow != null)
{
var SundayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_SunLocale.ClientID %>");
var MondayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_MonLocale.ClientID %>");
var TuesdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_TuesLocale.ClientID %>");
var WednesdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_WedLocale.ClientID %>");
var ThursdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_ThursLocale.ClientID %>");
var FridayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_FriLocale.ClientID %>");
var SaturdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_SatLocale.ClientID %>");
if(currentCombo == "OFF" || currentCombo == "OFFICE")
{
if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SunActivity")
{
SundayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_MonActivity")
{
MondayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_TuesActivity")
{
TuesdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_WedActivity")
{
WednesdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_ThursActivity")
{
ThursdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_FriActivity")
{
FridayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SatActivity")
{
SaturdayLoc.disable();
}
sender.hideDropDown();
}
else if(currentCombo != "OFF" && currentCombo != "OFFICE")
{
if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SunActivity")
{
SundayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_MonActivity")
{
MondayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_TuesActivity")
{
TuesdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_WedActivity")
{
WednesdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_ThursActivity")
{
ThursdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_FriActivity")
{
FridayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SatActivity")
{
SaturdayLoc.enable();
}
sender.hideDropDown();
}
}
现在真正奇怪的(也许是发生这种情况的根本原因)是,当我删除上面的代码时,正好有一半的错误指出了这些 Web 表单元素 ID 名称消失。然而,只有一半——不是全部,这是没有意义的,因为我删除了所有要求 Web 表单元素 ID 的 JavaScript 代码部分。
删除所有相关的 JavaScript 并双击 VS2005 中剩余的 7 个错误消息后,它们都将我带到页面中的第一行代码,即:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DistrictSchedule.aspx.vb" Inherits="FieldOperations_DistrictSchedule" %>
我自己和我的同事都不知道发生了什么。当我消除一半的错误时,至少该页面将执行。然而,从代码来看,这一切都应该有效。
其他错误信息: 我应该提到的是,我试图找到的那些 Web 表单元素 ID 仅当我的 RadGrid 处于编辑模式时才存在,因此它们最初并不存在是有道理的。无论如何,这不应该导致站点瘫痪错误,尽管无论出于何种原因。最后,引发错误的特定行是使用 $find 的行,并且使用 $find 获取值的变量的行也会引发错误。
无论谁能告诉我发生了什么事,都会给我很大的帮助。我先谢谢你了。
So I have the error mentioned in the title when I try to build my web site through the file menu. The code that causes this is below (JavaScript that appears in the body tag):
if(editedRow != null)
{
var SundayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_SunLocale.ClientID %>");
var MondayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_MonLocale.ClientID %>");
var TuesdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_TuesLocale.ClientID %>");
var WednesdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_WedLocale.ClientID %>");
var ThursdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_ThursLocale.ClientID %>");
var FridayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_FriLocale.ClientID %>");
var SaturdayLoc = $find("<%= FieldOpsScheduler_ctl00_ctl05_RCB_SatLocale.ClientID %>");
if(currentCombo == "OFF" || currentCombo == "OFFICE")
{
if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SunActivity")
{
SundayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_MonActivity")
{
MondayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_TuesActivity")
{
TuesdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_WedActivity")
{
WednesdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_ThursActivity")
{
ThursdayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_FriActivity")
{
FridayLoc.disable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SatActivity")
{
SaturdayLoc.disable();
}
sender.hideDropDown();
}
else if(currentCombo != "OFF" && currentCombo != "OFFICE")
{
if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SunActivity")
{
SundayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_MonActivity")
{
MondayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_TuesActivity")
{
TuesdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_WedActivity")
{
WednesdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_ThursActivity")
{
ThursdayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_FriActivity")
{
FridayLoc.enable();
}
else if(rcbID == "FieldOpsScheduler_ctl00_ctl05_RCB_SatActivity")
{
SaturdayLoc.enable();
}
sender.hideDropDown();
}
}
Now what's really weird (and perhaps is an underlying cause of this occurring) is that when I delete the above code, exactly half the errors pointing out those web form element ID names go away. However only half -- not all of them, which doesn't make sense seeing as I got rid of all parts of the JavaScript code that ask for the web form elements' IDs.
After deleting all relevant JavaScript and double-clicking the remaining seven error messages in VS2005, they all take me to the very first line of code in the page, which is this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DistrictSchedule.aspx.vb" Inherits="FieldOperations_DistrictSchedule" %>
Myself nor my coworker knows what the deuce is going on. When I get rid of half of the errors, at least the page will execute. However it all SHOULD work, judging by the code..
Additional Error Info:
I should mention that those web form element IDs that I'm trying to find exist ONLY when my RadGrid is in edit mode, so it would make sense that they're not originally there to begin with. Regardless, this should NOT be causing a site-crippling error, although for whatever reason it is. Lastly, the specific lines throwing the error are the ones utilizing $find, and the lines utilizing the vars that $find gets values for throw the error too.
Whoever out there who can tell me what is going on would be a MAJOR help. I thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,当我随机浏览其他一些页面寻找有关
find()
和 Telerik 的信息时,我想到了解决这个问题的好主意。我注意到,在某些情况下,您会遇到以下情况:而在其他情况下,您会遇到以下情况:
事实证明,这两行非常相似的代码是不可互换的,尽管乍一看人们可能认为它们是可以互换的。具体来说,在我的例子中,消除所有这些非常烦人的错误的方法是使用不带括号和百分号的第二行。
关于为什么第二行在我的情况下有效而不是第一行,我的理论是,当选择编译/构建网站时,如果您使用像第一行这样的代码,编译器希望立即通过 .aspx 页面上的标记语法创建您的对象在运行时。就我而言,当我的 RadGrid 进入编辑模式时,会动态创建“FieldOpsScheduler_blahblahblah”(因此,不是在运行时立即创建)。
无论如何,希望我的经验能够帮助遇到这个问题或类似问题的人。
So I got my bright-idea for a fix to this when I randomly browsed some other page looking for information regarding
find()
and Telerik. I noticed in some cases you have things like:And in other cases you have things like:
Turns out, these two quite similar lines of code are not interchangeable, though at first-glance one might think they are. Specifically what got rid of ALL of these utterly-annoying errors in my case was to use the second line without the brackets and percent signs.
My theory as to why line two works in my case and not line one, is that when selecting Compile/Build Website, if you utilize code like line one, the compiler expects your object to be created via markup syntax on the .aspx page immediately at runtime. In my case, the "FieldOpsScheduler_blahblahblah" was being dynamically created when my RadGrid gets put into edit mode (so, not immediately at runtime).
Anyway hopefully my experience will help someone out there who runs into this problem or a similar one.
很高兴您找到了自己的解决方案。为了进一步澄清,这是发生的事情。
上面是 Response.Write 的简写。因此,当您使用以下代码行时:
您告诉您的 ASPX 页面获取服务器端控件的 ClientID,然后在处理页面时将该 ID 输出到 JavaScript,从而在呈现的页面上产生类似这样的内容:
在使用 ASP.NET 进行 JavaScript 编程时经常使用此方法来获取服务器端控件的客户端 HTML ID,因为 ASP.NET 可以在运行时动态调整 HTML ID。此代码可确保您始终在 JavaScript 中拥有正确的 ID,无论 ASP.NET 容器命名如何调整。
如果您的客户端 ID 是静态的(您在设计时设置的内容就是呈现到页面的内容),那么您不需要查找 ClientID,而是可以这样写:
Where "SomeControlID. .." 是您所定位的控件的实际 HTML ID。 JavaScript
$find
方法将直接查找该 HTML ID 并获取对 HTML 对象的引用。希望这有助于解决“为什么”。
Glad you found your own solution. For further clarification, here's what's happening.
The above is shorthand for
Response.Write
. So, when you use the following line of code:You are telling your ASPX page to get the ClientID of your server-side control and then output that ID to your JavaScript when the page is processed, resulting in something like this on the rendered page:
This is often used when doing JavaScript programming with ASP.NET to get the client-side HTML ID of server-side controls because ASP.NET can dynamically adjusts HTML IDs at runtime. This code ensures you always have the correct ID in JavaScript regardless of ASP.NET container naming adjustments.
If your client ID is static (what you set at design-time is what renders to the page), then you don't need the ClientID look-up and can instead write this:
Where "SomeControlID..." is the actual HTML ID of the control you're targeting. The JavaScript
$find
method will look for that HTML ID directly and get a reference to the HTML object.Hope that helps with the "why."