多个通用用户控件,但一个.js文件 [英] Multiple Common User Control but one .js file

查看:55
本文介绍了多个通用用户控件,但一个.js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将一个JS文件包含到aspx页面中.
宿主页面具有用户控件的多个实例.
每个用户控件都有自己的网格.我已经定义了
每个UserControl中的Javascript变量以获取UserControl
特殊网格.
JS文件具有为Grid编写的多种通用功能.
但是我在访问特定于用户控件的网格时遇到问题,

I have include a JS file in to a aspx page.
The host page has multiple instances of the user control.
and each user control has there own grid. i have defined a
Javascript variable in each UserControl to get the UserControl
Spcific Grid.
The JS file has miltiple common function written for Grid.
but i have a problem to access the User Control specific grid,
Is there a way to access user control specific grid?

推荐答案

创建用户控件后,我们将ID分配给用户控件中使用的控件.此外,当用户控件添加到页面上时,它也包含ID.例如:

1.我有一个用户控件,其中有一个按钮.按钮的唯一ID是"btnTest" .
2.现在,我将此控件添加到我的Page中,并将其ID设置为"uc1" .

呈现页面时,它包含在用户控件中创建的按钮的唯一ID,并且可以通过查看源代码" 选项进行查看.

使用此ID,您可以获取在用户控件中创建的数据网格的对象.要获取对象,请使用javascript中的 document.getElementById 函数.

希望这能回答您的问题.
When a user control is created, we assign an Id to the control used in our User Control. Further when the user control is added on a page it also contains Id. For example:

1. I have a user control in which I have a button. The unique Id of the button is "btnTest".
2. Now I added this control to my Page and gave it the id as "uc1".

At the time the page is rendered it contains a unique id for the button which was created in User Control and it can be viewed by "View Source" option.

With this id you can get the object of the datagrid created in User Control. To get the object use the document.getElementById function in your javascript.

Hope this answer your question.


当您从网格中调用任何方法时,请在用户控件中使用"this"关键字.

使用"this"会将特定的网格对象发送到JS方法,您可以根据需要进行操作.
例如:
Use ''this'' keyword in your usercontrols when you call any method from the grid.

Using ''this'' would send that specific grid object to the JS methods and you can play around it as required.
ex:
onSort="PleaseSortMe(this)";


这篇关于多个通用用户控件,但一个.js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆