如何通过 JavaScript 获取 ASP DetailsView 内部的控制权?
有人能告诉我如何使用 javascript 在 ASP DetailsView 中查找控件吗? 我的要求是在按钮的客户端上显示一个确认框,单击该复选框是否被选中。
下面是在没有 DetailsView 的情况下工作的代码
<script type="text/javascript" language="javascript">
function confirmation() {
var chkbx = document.getElementById("chkbox4PubnOrder");
if (chkbx.checked == false) {
var answer = confirm('Are you sure to add a feature which be published');
if (answer) {
return true;
}
else {
return false;
}
}
else {
return true;
}
}
</script>
,其中 chkbox4PubnOrder 是一个 asp 复选框。在查看详细信息时,上述代码无法找到复选框
我触发了 asp 按钮的 onclientclick 事件 -
OnClientClick="if(!confirmation()) return false;"
请帮忙......
could anybody describe me how to find a control inside a ASP DetailsView using javascript?
my requirement is to display a confirm box on a button's client click that checkbox is checked or not.
Here is the code working without DetailsView-
<script type="text/javascript" language="javascript">
function confirmation() {
var chkbx = document.getElementById("chkbox4PubnOrder");
if (chkbx.checked == false) {
var answer = confirm('Are you sure to add a feature which be published');
if (answer) {
return true;
}
else {
return false;
}
}
else {
return true;
}
}
</script>
where chkbox4PubnOrder is a asp checkbox. In case of details view, the above code is unable to find the checkbox
And I fire this onclientclick event of asp button-
OnClientClick="if(!confirmation()) return false;"
Please help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ASP.Net 为服务器端控件生成自己的 ID。
您可以编写
<%= chkbox4PubnOrder.ClientID %>
来获取此生成的 ID。ASP.Net generates its own IDs for server-side controls.
You can write
<%= chkbox4PubnOrder.ClientID %>
to get this generated ID.或者,您始终可以在浏览器中查看页面的源代码,并查看它为控件提供的 ID。它通常是根据页面名称和您可能放入的任何附加“层”(例如用户控件等)构建的。
Or you can always view the source of the page after it's in the browser and see what ID it gave to the control. It's typically built off the page name and any additional "layers" you may have put in such as user controls, etc.
<%= chkbox4PubnOrder.ClientID %>
也不起作用,因为该控件位于 ASP DetailView 内部。我尝试了与在 GridView 或数据网格内搜索控件相同的方式。那也不太幸运。我尝试获取如下控件
此代码不会将 chkbx 显示为
null
即这找到了详细信息视图中的复选框,但找不到它是否被选中。是否需要打字?如果是,请描述如何?<%= chkbox4PubnOrder.ClientID %>
also does not work as the control is inside the ASP DetailView. i tried the same manner as we search a control inside a GridView or datagrid. That was also no luck.i tried to get the control as below
This code does not show chkbx as
null
i.e. this finds the checkbox inside detailsview but could not find it is checked or not. Is the typecasting is needed? if yes then please describe how?