开发者

how to get control inside ASP DetailsView through javasscript?

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


ASP.Net generates its own IDs for server-side controls.

You can write <%= chkbox4PubnOrder.ClientID %> to get this generated 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 %> 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜