2

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.

2 Answers 2

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


Sign up to request clarification or add additional context in comments.

6 Comments

I was trying that yesterday with some co-workers help. That assigns those to the span tag.
You mean that the 'onchange' attribute is set on the <span> that asp.net generates along with the checkbox ?
Yes. Sorry, I just got a new job and this is the first time I'm running page design.
Don't be sorry. ASP.net generates too much unnecessary html in my opinion and it's not easily controllable. Found this post about this problem. Have a look.
That did not help :( While the attribute showed up in the input and not span, the method still did not get called.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.