Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript<;%=MyProperty%>;_Javascript_Asp.net - Fatal编程技术网

JavaScript<;%=MyProperty%>;

JavaScript<;%=MyProperty%>;,javascript,asp.net,Javascript,Asp.net,在JavaScript中使用这种结构有哪些限制。在我的codeBehind中,我有属性,在get上,它有相当复杂的逻辑。它调用其他方法等等,结果我得到了空字符串,尽管调试时显示它返回了良好的值。我想知道在render方法中运行这种类型的代码时我能做些什么 使用这种方法呈现JavaScript没有任何限制。您只需确保您的属性在各种情况下都可用,例如标准HTTP get、回发等。当然,您必须确保该属性根据需要正确转义/JavaScript编码,即如果它是包含引号的字符串值等。我一直在使用它 我还建议

在JavaScript中使用这种结构有哪些限制。在我的codeBehind中,我有属性,在get上,它有相当复杂的逻辑。它调用其他方法等等,结果我得到了空字符串,尽管调试时显示它返回了良好的值。我想知道在render方法中运行这种类型的代码时我能做些什么

使用这种方法呈现JavaScript没有任何限制。您只需确保您的属性在各种情况下都可用,例如标准HTTP get、回发等。当然,您必须确保该属性根据需要正确转义/JavaScript编码,即如果它是包含引号的字符串值等。

我一直在使用它

我还建议您执行以下操作:

this.txtProjectName = $('#<%=this.txtProjectName.ClientID %>');

+1.在执行此操作时,有一件事总是让我感到困惑——当值是字符串时,忘记将块用引号括起来。似乎每次这样做时我至少会这样做一次。服务器和js的这种硬耦合让我非常难过:(即使在C#中,“某些”事物本质上是重耦合的。@prisonerZERO这更像是ASP.NET的一般性失败和无法用其控件创建合理或语义HTML。我不同意。在.NET中,“某些”事物本质上是高度耦合的。这与C#@Raynos无关好吧……也许更好的解释方式是“某些事物本质上是相互联系的”.@Raynos我不想让你认为我不同意你的观点……我同意重耦合应该谨慎使用……就像反规范化一样。但即使是反规范化这样的东西(有时)也有有效的用途。
<script type="text/javascript">

    var projectDialog = (function($) {
        var publicInstances = {};

        // ***********************
        // form
        publicInstances.form = form;
        function form(controller) {

            /// <summary></summary>
            var self = this;

            /// <summary></summary>
            this.controller = controller;
            /// <summary></summary>
            this.validationController = null;

            this.hidAsOf = $('#<%=this.hidAsOf.ClientID %>');
            this.hidProjectKey = $('#<%=this.hidProjectKey.ClientID %>');
            this.hidMode = $('#<%=this.hidMode.ClientID %>');
            this.ddlClients = $('#<%=this.ddlClients.ClientID %>');

            this.txtProjectName = $('#<%=this.txtProjectName.ClientID %>');
            this.txtProjectNumber = $('#<%=this.txtProjectNumber.ClientID %>');
            this.txtProjectManager = $('#<%=this.txtProjectManager.ClientID %>');
            this.txtProjectDescription = $('#<%=this.txtProjectDescription.ClientID %>');
            this.ddlEMREProductivityCurve = $('#<%=this.ddlEMREProductivityCurve.ClientID %>');
            this.txtStartDate = $('#<%=this.txtStartDate.ClientID %>');
            this.txtEndDate = $('#<%=this.txtEndDate.ClientID %>');
            this.txtEngineeringHours = $('#<%=this.txtEngineeringHours.ClientID %>');
            this.txtDirectHours = $('#<%=this.txtDirectHours.ClientID %>');
            this.txtIndirectHours = $('#<%=this.txtIndirectHours.ClientID %>');
            this.txtOtherHours = $('#<%=this.txtOtherHours.ClientID %>');
            this.txtARRThreshold = $('#<%=this.txtARRThreshold.ClientID %>');
            this.txtAppropriationHours = $('#<%=this.txtAppropriationHours.ClientID %>');
            this.txtAppropriationDollars = $('#<%=this.txtAppropriationDollars.ClientID %>');
            this.ibtnSaveProject = $('#<%=this.ibtnSaveProject.ClientID %>');
            this.imgClose = $('#<%=imgClose.ClientID %>');
            this.imgStartDate = $('#<%=imgStartDate.ClientID %>');
            this.imgEndDate = $('#<%=imgEndDate.ClientID %>');

            this.disabledCssClass = "textbox-locked";

            /// <summary></summary>
            this.initialize = function() {

                var context = $(self.controller.container);
                var contentArea = $(self.controller.contentArea, context);

                self.validationController = new validation.controller(contentArea);

                if(self.controller.readOnly == true)
                    self.disableForm();

                /// <summary>Set defaults.</summary>
                self.ddlClients.attr('disabled', 'disabled');

                /// <summary>Register click events.</summary>
                self.ibtnSaveProject.click(function() { self.controller.save(); });
                self.imgClose.click(function() { self.close(); });

                /// <summary>Register rounders.</summary>
                $('input.rounder-decimal', context).numericRounder();

                /// <summary>Register keypress events.</summary>
                $('input.rounder-decimal', context).keypress(function(e) {
                    return enforceValueAsDollar(e, this.val);
                });

                /// <summary>Register change events.</summary>
                $('input.rounder-decimal', context).change(function() {
                    var element = $(this);
                    var value = element.extractValue();
                    var formatted = $.formatNumber(value.toString(), { format: "#,###.00", locale: "us" });

                    if (isNaN(value))
                        formatted = 0;

                    element.val(formatted);

                    if (!element.is('.textbox-total'))
                        self.calculateAppropriationHours();
                });
            };
            /// <summary></summary>
            this.disableStartDate = function(){
                self.imgStartDate.remove();
                self.txtStartDate.removeClass(self.disabledCssClass);
                self.txtStartDate.addClass('TextBoxLocked');
            };
            /// <summary></summary>
            this.disableForm = function() {

                self.disableStartDate();

                self.ddlEMREProductivityCurve.attr('disabled', true);

                self.txtProjectName.attr('disabled', true);
                self.txtProjectNumber.attr('disabled', true);
                self.txtProjectManager.attr('disabled', true);
                self.txtProjectDescription.attr('disabled', true);

                self.txtEndDate.attr('disabled', true);
                self.txtEngineeringHours.attr('disabled', true);
                self.txtDirectHours.attr('disabled', true);
                self.txtIndirectHours.attr('disabled', true);
                self.txtOtherHours.attr('disabled', true);
                self.txtARRThreshold.attr('disabled', true);
                self.txtAppropriationHours.attr('disabled', true);
                self.txtAppropriationDollars.attr('disabled', true);

                self.txtProjectName.addClass(self.disabledCssClass);
                self.txtProjectNumber.addClass(self.disabledCssClass);
                self.txtProjectManager.addClass(self.disabledCssClass);
                self.txtProjectDescription.addClass(self.disabledCssClass);

                self.txtEndDate.addClass(self.disabledCssClass);
                self.txtEngineeringHours.addClass(self.disabledCssClass);
                self.txtDirectHours.addClass(self.disabledCssClass);
                self.txtIndirectHours.addClass(self.disabledCssClass);
                self.txtOtherHours.addClass(self.disabledCssClass);
                self.txtARRThreshold.addClass(self.disabledCssClass);
                self.txtAppropriationHours.addClass(self.disabledCssClass);
                self.txtAppropriationDollars.addClass(self.disabledCssClass);

                self.ibtnSaveProject.css('display', 'none');
            };
            /// <summary></summary>
            this.close = function() {
                self.clear();
                closeSubForm('<%=divProjectDialog.ClientID %>');
            };
            /// <summary></summary>
            this.clear = function() {

                self.validationController.clear();

                self.hidProjectKey.val('0');

                self.txtProjectName.val('');
                self.txtProjectNumber.val('');
                self.txtProjectManager.val('');
                self.txtProjectDescription.val('');

                self.txtStartDate.val('');
                self.txtEndDate.val('');
                self.txtEngineeringHours.val('0.00');
                self.txtDirectHours.val('0.00');
                self.txtIndirectHours.val('0.00');
                self.txtOtherHours.val('0.00');
                self.txtARRThreshold.val('0.00');
                self.txtAppropriationHours.val('0.00');
                self.txtAppropriationDollars.val('0.00');
            };
            /// <summary></summary>
            this.isOpen = function() {
                var context = $(self.controller.container)
                return (context.css('opacity') == '0') ? false : true;
            };
            /// <summary></summary>
            this.isValid = function() {

                self.validationController.clear();

                var key = parseInt(self.hidProjectKey.val());

                if (self.ddlClients.val().length == 0) {
                    var validator = self.validationController.getValidator(self.ddlClients.id());
                    validator.appendMessage("Please choose an option.");
                }

                if (self.txtProjectName.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtProjectName.id());
                    validator.appendMessage("Cannot be empty.");
                }

                if (self.hidProjectKey.val().length > 0) {

                    var key = parseInt(self.hidProjectKey.extractValue());
                    if (key > 0) 
                    {
                        if (self.ddlEMREProductivityCurve.val().toLowerCase() == 'none') {
                            var validator = self.validationController.getValidator(self.ddlEMREProductivityCurve.id());
                            validator.appendMessage("Please choose an option.");
                        }

                        if (self.txtStartDate.val().length == 0) {
                            var validator = self.validationController.getValidator(self.txtStartDate.id());
                            validator.appendMessage("Click calendar to choose a valid date.");
                        }

                        if (self.txtEndDate.val().length == 0) {
                            var validator = self.validationController.getValidator(self.txtEndDate.id());
                            validator.appendMessage("Click calendar to choose a valid date.");
                        }

                        if ((self.txtStartDate.val().length > 0) && (self.txtEndDate.val().length > 0)) {
                            var startDate = new Date(self.txtStartDate.val());
                            var endDate = new Date(self.txtEndDate.val());

                            if (startDate > endDate) {
                                var validator = self.validationController.getValidator(self.txtEndDate.id());
                                validator.appendMessage("End date must br greater than start date.");
                            }
                        }
                    }
                }

                if (self.txtARRThreshold.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtARRThreshold.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtARRThreshold.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtARRThreshold.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtEngineeringHours.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtEngineeringHours.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtEngineeringHours.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtEngineeringHours.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtDirectHours.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtDirectHours.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtDirectHours.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtDirectHours.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtIndirectHours.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtIndirectHours.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtIndirectHours.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtIndirectHours.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtOtherHours.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtOtherHours.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtOtherHours.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtOtherHours.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtAppropriationHours.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtAppropriationHours.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtAppropriationHours.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtAppropriationHours.id());
                    validator.appendMessage("Is not a valid number.");
                }

                if (self.txtAppropriationDollars.val().length == 0) {
                    var validator = self.validationController.getValidator(self.txtAppropriationDollars.id());
                    validator.appendMessage("Cannot be empty.");
                }
                else if (isNaN(self.txtAppropriationDollars.extractValue())) {
                    var validator = self.validationController.getValidator(self.txtAppropriationDollars.id());
                    validator.appendMessage("Is not a valid number.");
                }

                self.validationController.displayAll();

                return (self.validationController.hasErrors() == true) ? false : true;
            };
            /// <summary></summary>
            this.calculateAppropriationHours = function() {

                var engineeringHours = (+self.txtEngineeringHours.extractValue()) || 0;
                var directHours = (+self.txtDirectHours.extractValue()) || 0;
                var indirectHours = (+self.txtIndirectHours.extractValue()) || 0;
                var otherHours = (+self.txtOtherHours.extractValue()) || 0;

                var total = engineeringHours + directHours + indirectHours + otherHours;

                self.txtAppropriationHours.val(total).change();
            };
            /// <summary></summary>
            this.populateFrom = function(project) {

                self.clear();

                self.hidProjectKey.val(project.key);

                // Drop-Down
                self.ddlClients.val(project.clientKey);

                self.txtProjectName.val(project.projectName);
                self.txtProjectNumber.val(project.number);
                self.txtProjectManager.val(project.projectManager);
                self.txtProjectDescription.val(project.description);

                // Drop-Down
                self.ddlEMREProductivityCurve.val(project.productivityCurveType);

                if(project.startDate != null)
                    self.txtStartDate.val(project.startDate);

                if(project.startDate != null)
                    self.txtEndDate.val(project.endDate);

                self.txtEngineeringHours.val(project.engineeringHours);
                self.txtDirectHours.val(project.directHours);
                self.txtIndirectHours.val(project.indirectHours);
                self.txtOtherHours.val(project.otherHours);
                self.txtARRThreshold.val(project.arrThreshold);
                self.txtAppropriationHours.val(project.appropriationHours);
                self.txtAppropriationDollars.val(project.appropriationAmount);

                self.txtEngineeringHours.change();
                self.txtDirectHours.change();
                self.txtIndirectHours.change();
                self.txtOtherHours.change();
                self.txtARRThreshold.change();
                self.txtAppropriationHours.change();
                self.txtAppropriationDollars.change();
            };
        };

        return publicInstances;
    })(jQuery);
</script>