DevExpress:如何获取控件客户端的实例并访问其客户端成员?
我有一个来自 DexExpress 的 DateEdit 控件,需要使用 Javascript 从中获取日期值。从概念上讲,我正在寻找这样的东西:
var d = $("dpEndDate").GetDate();
他们的 API 参考表明 .GetDate() 是一个成员,但我只需要知道如何获取包含此成员的对象的客户端实例。
I have a DateEdit control from DexExpress and need to get the date value from it using Javascript. Conceptually, I am looking for something like this:
var d = $("dpEndDate").GetDate();
Their API reference indicates that .GetDate() is a member, but I just need to know how to acquire a client-side instance of the object that contains this member.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
必须指定 ClientInstanceName 属性(对于 ASP.NET WebForms)和“Name”属性(对于 ASP.NET MVC)以启用控件的客户端编程对象:
It is necessary to specify the ClientInstanceName property (for the ASP.NET WebForms) and the “Name” property (for the ASP.NET MVC) to enable control’s client-side programmatic object:
如果您正在开发基于多个需要能够相互交互的 DevExpress 控件的用户控件,并且您将在给定页面上拥有多个用户控件实例,那么最好使用 DevExpress ' window.aspxGetControlCollection() 与 DevExpress 控件的 ClientID 如下所示:这样
做的缺点是,您通常必须在后面的代码中构建客户端事件处理程序,以便可以轻松访问 DevExpress 控件的 ClientID,例如所以。
或者创建一个 JS 对象来处理客户端操作并重写渲染方法以添加一些脚本来创建具有所需 ClientID 的实例。
JS 实例:
渲染覆盖:
使用第二种方法时,假设您将公共字符串属性 ClientInstanceName 添加到用户控件,并在标记中为其指定了一个值。
If you're developing a user control based on multiple DevExpress controls that need to be able to interact with each other and you're going to have more than one instance of your user control on a given page, then it is best to use DevExpress' window.aspxGetControlCollection() with the ClientID of the DevExpress control like so:
The downside of this is that you've typically got to build client side event handlers in the code behind where you've got easy access to the DevExpress control ClientIDs like so.
Either that or create a JS object to handle your client side actions and override the render method to add a some script to create this instance with the needed ClientIDs.
JS Instance:
Render Override:
With the second method there's an assumption that you added a public string attribute ClientInstanceName to your user control and have given that a value in the markup.
尝试:
原因是 ASP.NET ClientID 由控件树中的命名容器限定,因此最终可能会类似于“ctl1_ct12_ct12_dpEndDate”。
您可以让 ASP.NET 4.0 不使用此分层命名,但默认情况下它是启用的。
Try:
The reason is that ASP.NET ClientIDs are qualified by their naming-container in the control tree, so may end up as something like "ctl1_ct12_ct12_dpEndDate".
You can get ASP.NET 4.0 to not use this hierarchical naming, but it's on by default.