如何通过 JavaScript 获取 ASP DetailsView 内部的控制权?

发布于 2024-10-28 09:06:41 字数 800 浏览 3 评论 0原文

有人能告诉我如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

狠疯拽 2024-11-04 09:06:41

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.

A君 2024-11-04 09:06:41

或者,您始终可以在浏览器中查看页面的源代码,并查看它为控件提供的 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.

秉烛思 2024-11-04 09:06:41

<%= chkbox4PubnOrder.ClientID %> 也不起作用,因为该控件位于 ASP DetailView 内部。我尝试了与在 GridView 或数据网格内搜索控件相同的方式。那也不太幸运。

我尝试获取如下控件

<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 即这找到了详细信息视图中的复选框,但找不到它是否被选中。是否需要打字?如果是,请描述如何?

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

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

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文