language中文

Sys.InvalidOperationException: The id property can't be set on this object.

visibility 279 comment 0 access_time 13 years ago
今天在做一个Ajax控件的时候,遇到了一个错误
Sys.InvalidOperationException: The id property can't be set on this object.
也就是说在这个对象上不能设置id属性
但是msdn文档里边写的明明是可以的
$create(Juice.SysUI.Prompt, {"content":"","height":{"IsEmpty":true,"Type":1,"Value":0},"id":"juiceprompt","onCancelBtnID":"","onCancelScript":"","onCloseRefresh":true,"onCloseScript":"","onOKBtnID":"","onOKScript":"","title":"测试","width":{"IsEmpty":true,"Type":1,"Value":0}}, null, null, $get("ctl00_adminContentPlaceHolder_prompt1"));
我是想通过$find("juiceprompt")来获得客服端组件的实例
所以才设置了id属性
但是却出错了
百度了下没有找到任何解决方案 于是 google了下 看到确实有很多人遇到了这个问题
http://forums.asp.net/t/1212627.aspx最终在这里找到了问题的解决方法

这篇文章中有个人说的方法确实可以解决 因为我的Juice.SysUIPrompt确实是继承自Sys.UI.Control的 如果改成Behavior的话就不会出现这个错误的

Hi,

Thank you for your post!

I think it is normal!

Here is the reason:

We cann't change the ID property of a Dom object at client side via javascript, the Id cann't be changed after the DOM object is explained by browser.

The following code is supposed to change the ID property of a DOM object which is not allowed. so the error fired.

$create(Demo.HoverButton, {id:'testId',text: 'A HoverButton Control',element: {style: {fontWeight: "bold", borderWidth: "2px"}}}, {click: start, hover: doSomethingOnHover, unhover: doSomethingOnUnHover},null, $get('Button1'));

Sys.UI.Behavior works fine beause Behavior don't render as DOM objects, they are rendered as plain javascript objects.

If you have further questions,let me know!

Best Regards,

所以他的说法应该是正确的

可是文档里边偏偏说的是可以设置id属性的 因为本来Control和Behavior都是继承自Sys.Component的嘛

再继续看下去哈哈官方团队给了解释 是文档除了错,唉浪费了我这么多时间

It's the documentation that's wrong here. The id can't be set on a control. The id of a control is the id of the element it's attached to. I'll make sure the documentation is updated.

Thanks for the feedback.

Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.

P.S.:查询代码这些 Google比百度还是强多了
info Last modified by Raymond 13 years ago copyright This page is subject to Site terms.

Subscribe newsletter

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts