0

I hope I will be able to explain my problem clearly.

Scenario:

Asp.net web page with UpdatePanel. Some properties of controls are changeable via UI trigger and are set in jQuery (for faster response, as this page is expected to accept input data of at least 500 records per day).

Example below, (if written in c# code, the logic is like this: txtIDNumber.Enabled = chkIsReceiptRequired.Checked; rfvIDNumber.Enabled = chkIsReceiptRequired.Checked;):

Markup:

<asp:CheckBox ID="chkReceiptRequired" runat="server" Text="Receipt required" />
<asp:TextBox runat="server" ID="txtIDNumber" Width="150px" style="float: left;" />
<asp:RequiredFieldValidator ID="rfvIDNumber" runat="server" ForeColor="Red" 
     ErrorMessage="Enter ID No." ControlToValidate="txtIDNumber" ValidationGroup="save" />

Snippet of default jQuery code (upon page load, chkReceiptRequired is unchecked, validator and textbox will only be enabled upon ticking chkReceiptRequired):

<script type="text/javascript">
    function pageLoad(){
        $('input[id$=_txtIDNumber]').prop('disabled', true);
        ValidatorEnable($("[id$='rfvIDNumber']")[0], false);

        $('input[id$=_chkReceiptRequired]').change(function () {
            $('input[id$=_txtIDNumber]').prop('disabled', !$(this).is(':checked'));
            $('input[id$=_txtIDNumber]').val(!$(this).is(':checked') ? '' : $('input[id$=_txtIDNumber]').val());
            ValidatorEnable($("[id$='rfvIDNumber']")[0], $(this).is(':checked'));
        });
    }
</script>

I'm using this same page to load the data here to perform record update. Code snippet of data loading:

var maintableComponent = new MainTableComponent();
var maintableData = maintableComponent.GetMainTableDataById(rowId);

chkReceiptRequired.Checked = maintableData.IsReceiptRequired.Value;
txtIDNumber.Text = maintableData.IDNumber;
//todo: enable txtIDNumber and rfvIDNumber from here

The problem: by right, upon page render for update, because chkReceiptRequired is checked, supposedly txtIDNumber should be enabled. But my problem is, it is not. What can I do to enable the txtIDNumber and rfvIDNumber upon data loading from code-behind?

*I have already tried this link and this but it doesn't seem to work.

Please, please help me. The snippets I posted here are just one of many jQuery validations that I desperately need to address. Thanks in advance.

3
  • Can you screenshot the thing that's suppoused to be checked in your site? It might help us understand your problem better (: Commented Feb 20, 2015 at 19:43
  • Another question: Did you try simply txtIDNumber.Checked=true; in the codebehind? Commented Feb 20, 2015 at 19:44
  • Yes. I included the code above. And thanks, I managed to figure it out. :) Commented Feb 21, 2015 at 8:20

1 Answer 1

0

Feeling incredibly stupid right now. Figured out how to fix it after sleeping it off. :P

I just changed the default jQuery code to this:

var isReceiptRequired = $('input[id$=_chkReceiptRequired]').is(':checked');

$('input[id$=_txtIDNumber]').prop('disabled', !isReceiptRequired);
ValidatorEnable($("[id$='rfvIDNumber']")[0], isReceiptRequired);

I just remembered that the last thing in the page-cycle is rendering it on the page so the jQuery can be manipulated by the values set in the control from code-behind.

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

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.