admin管理员组

文章数量:1431406

I have a few controls designed to verify certain data before a user may do a soft delete on server data.

The error:

Compiler Error Message: CS1061: 'ASP.editdivision_aspx' does not contain a definition for 'show_confirm' and no extension method 'show_confirm' accepting a first argument of type 'ASP.editdivision_aspx' could be found (are you missing a using directive or an assembly reference?)

Line 28:         <td><asp:TextBox runat="server" ID="txtDivisionName"  Width="250"  /></td>
Line 29:     </tr>
Line 30:     <tr><td><asp:CheckBox ID="chkDelete" runat="server" Text="Delete" OnCheckedChanged="show_confirm" /></td></tr>
Line 31:     <tr><td><asp:Button ID="btnSave" runat="server" Text="Save" OnClick="SaveClick" /></td></tr>
Line 32: </table>

The script:

<script type="text/jscript" >
function show_confirm() {
    PageMethods.VerifyDelete(CallSuccess, CallFailed);
}
function CallSuccess(res, destCtrl) {}
function CallFailed(res, destCtrl) {
    var r = confirm("There are active Campaigns in this Division!\nAre you sure you want to proceed?");
    if (r == true) {
        PageMethods.Save();
        //alert("Division and related Campaigns deleted.");
    }
}
</script>

I have been unable to determine why I am getting this runtime error. I am new to asp and javascript so I am sure it is something simple I missed, but I have been searching for 2 days on what the problem is.

I have a few controls designed to verify certain data before a user may do a soft delete on server data.

The error:

Compiler Error Message: CS1061: 'ASP.editdivision_aspx' does not contain a definition for 'show_confirm' and no extension method 'show_confirm' accepting a first argument of type 'ASP.editdivision_aspx' could be found (are you missing a using directive or an assembly reference?)

Line 28:         <td><asp:TextBox runat="server" ID="txtDivisionName"  Width="250"  /></td>
Line 29:     </tr>
Line 30:     <tr><td><asp:CheckBox ID="chkDelete" runat="server" Text="Delete" OnCheckedChanged="show_confirm" /></td></tr>
Line 31:     <tr><td><asp:Button ID="btnSave" runat="server" Text="Save" OnClick="SaveClick" /></td></tr>
Line 32: </table>

The script:

<script type="text/jscript" >
function show_confirm() {
    PageMethods.VerifyDelete(CallSuccess, CallFailed);
}
function CallSuccess(res, destCtrl) {}
function CallFailed(res, destCtrl) {
    var r = confirm("There are active Campaigns in this Division!\nAre you sure you want to proceed?");
    if (r == true) {
        PageMethods.Save();
        //alert("Division and related Campaigns deleted.");
    }
}
</script>

I have been unable to determine why I am getting this runtime error. I am new to asp and javascript so I am sure it is something simple I missed, but I have been searching for 2 days on what the problem is.

Share Improve this question edited Nov 16, 2011 at 16:35 BNL 7,1234 gold badges29 silver badges32 bronze badges asked Nov 16, 2011 at 16:26 scott.smartscott.smart 5385 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The attribute OnCheckedChanged requires a server-side event handler, not a javascript function.

Try the onchange attribute which is the standard html attribute for the client-side event:

<asp:CheckBox ID="chkDelete" runat="server" Text="Delete" onchange="show_confirm()" />


Edit:

It seems asp is generating a element and applies the 'onchange' on the span and not the .

Found this post that deals with this problem: Add client-side onchange handler to ASP.NET CheckBox control


This is what worked for me, onchange and OnClientClick did not work, onclick did:

    <asp:CheckBox ID="EnabledCheckBox" runat="server" OnClick="showDiv(this.checked);"/>
<div id="ShowDiv">Show me now</div>

Javascript:

function showDiv(show) {
  if (show) {
    $('#ShowDiv').show("slow");
  } else {
    $('#ShowDiv').hide("slow");
  }
}

本文标签: cCheckBox event can not find javascript functionStack Overflow