简体   繁体   中英

onclick event is not fired by input buttons inside a user controls

I've updated my .Net web application to use Framework 4.5, after the update, all the input buttons (not asp:Buttons), have stopped firing the onclick javascript code, this is only happening on those buttons that are inside a user control (.ascx).

Just for the record, user controls are neither being loaded dinamically nor inside update panels.

My buttons look like this

<input id="cb" onClick="myfunc()" type="button" value="Close" />

My user controls are included to the page as follows

<cc:actionbar id="theActionBar" runat="server"></cc:actionbar>

and the javascript function, which is also included within the user control, is

function myfunc() {

    if (confirm("Before closing, please make sure you saved any changes.\nAre you sure you want to close?") == true) {
        __doPostBack('theActionBar:theClose', '');
    }


}

this works just fine on Framework 3.5 and previous versions.

any idea why is this happening??? or how can I solve this?? I have tried several suggestions I've found over the internet and nothing seems to work.

Thanks in advance. .

I can't see an obvious reason, but have you considered simplifying your approach to avoid the custom javascript and hard-coded postback event reference? You can get exactly the same behaviour with an ASP.NET button's OnClientClick property:

    <asp:Button runat="server" ID="btnClose" Text="Close" OnClick="btnClose_Click" OnClientClick="return confirm('Before closing, please make sure you saved any changes.\nAre you sure you want to close?')" />

Returning false from the OnClientClick code or function prevents the postback.

Switching to this approach may be preferable and may even solve your issue if it's something to do with the postback event reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM