开发者

Ignore/disable usercontrol postback if javascript is enabled

开发者 https://www.devze.com 2023-01-21 03:17 出处:网络
I\'ve searched high and low for some resolution to this problem. Hopefully someone here can explain!!

I've searched high and low for some resolution to this problem. Hopefully someone here can explain!!

I create a usercontrol that uses .NET web controls, but I want to create a smoother user experience by avoiding full postbacks, so I write some JQUERY to capture click events on the client and in this way do the processing without going back to the server.

        $("#tblLedgerEntries :checkbox").click(function () {
            var value1 = $(this).closest("tr").find("td.invoiceAmount").html();
            var value2 = $('#<%=hdnTotalToPay.ClientID%>').html();
            CalculateTotalPayable(value1, value2, $(this).attr("checked"));
        });

All fine. Now someone comes to my site with javascript DISABLED. Let's assume I can detect whether javascript is enabled or otherwise. In this situation I will need to do the calculations I was doing on the client on the server which mean开发者_高级运维s I need to trigger a postback....

How do I do this.....I only want to trigger a full postback if javascript is disabled. I want to use the client script if javascript is enabled. If this is applying to checkboxes (UI recalculates a payable amount each time a user clicks a row checkbox), the only way I can see to trigger a postback is by using AutoPostBack=True....but this will always do a postback regardless of the client script.....arghhh.

Anyone know how to do this....or am I approaching this from the wrong angle?!??

Kind Regards

Richard


AutoPostBack = true is implemented via javascript. So if the user has javascript disabled, that won't work either. The only way to get a PostBack when javascript is disabled is with a usercontrol which gets rendered to the client as an <input type="submit" /> since that causes the browser to post the form. Any server controls which render javascript:__doPostBack() links will not work.


I guess you probably can do it using UpdatePanel:

http://msdn.microsoft.com/es-es/library/bb386454%28VS.90%29.aspx

http://ajax.net-tutorials.com/controls/updatepanel-control/

But of course, the logics will be in the server, using ajax or postbacks, not in the client.


$("#btnSave").attr('disabled', true); 
0

精彩评论

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