如何通过javasscript在ASP DetailsView中获取控件? [英] how to get control inside ASP DetailsView through javasscript?

查看:221
本文介绍了如何通过javasscript在ASP DetailsView中获取控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以有人描述我如何使用javascript在ASP细节视图中找到一个控件?
我的要求是在按钮的客户端单击时显示确认框,该复选框处于选中状态。

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.

这里是没有DetailsView工作的代码 -

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>

其中 chkbox4PubnOrder 是一个asp复选框。在详细信息视图的情况下,上面的代码无法找到复选框

我触发aspcl按钮的onclientclick事件 -

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;"

请帮助...

推荐答案

<%= chkbox4PubnOrder.ClientID%> 也不工作,因为控件位于ASP DetailView内。我尝试了同样的方式,我们搜索一个控件在GridView或datagrid。这也没有运气。

<%= 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.

我试图获得如下的控制

<script type="text/javascript" language="javascript">
function confirmation() {

    // first finding asp detailsview
    var detailsview = document.getElementById('<%= DetailsView1.ClientID %>');
    //then finding control inside the detailsview
    var chekbx = detailsview.getElementByTagName("chkbox4PubnOrder");

    if (chkbx.checked == false) {
        return confirm('Are you sure to add a feature which be published');
    }
    else {
        return true;
    }
}
</script>

此代码不会将chkbx显示为 null 即,找到detailsview中的复选框,但无法找到它被检查或不。是否需要类型转换?如果是,请描述如何?

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?

这篇关于如何通过javasscript在ASP DetailsView中获取控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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