How to get disabled input element value in ASP.Net

Last Reply one year ago By AnandM

Posted one year ago

hi

I ues below code to make Enabeld=false for textboxs when checked checkbox:

 <script type="text/javascript">
    $(function () {
        ApplyCss();
        // if checked.
        $('input[type=checkbox][id*=Chad]').on('ifChecked', function (event) {
            $("#Txtmatn").removeAttr("disabled");
            $("#Txtmatn").focus();
        });
        // if uncheckd.
        $('input[type=checkbox][id*=Chad]').on('ifUnchecked', function (event) {
            $("#Txtmatn").attr("disabled", "disabled");
        });

I define button in page to save textbox's text into database but here when I checked checkbox to make enabled=false it doesn't save any text into database from textbox

I want when ever enabled=false or true it saves data into database anyway

best regards

neda

 

Posted one year ago

Hi nedash,

The reason is simple, disabled inputs values aren't submitted to the server due to web-browsers submission limitation policy. The W3 spec says that input tags that are disabled are considered invalid and should not be submitted. Instead, use the readonly attribute:

<input type="text" readonly />

 

nedash says:
// if checked.
       $('input[type=checkbox][id*=Chad]').on('ifChecked', function (event) {
           $("#Txtmatn").removeAttr("disabled");
           $("#Txtmatn").focus();
       });
       // if uncheckd.
       $('input[type=checkbox][id*=Chad]').on('ifUnchecked', function (event) {
           $("#Txtmatn").attr("disabled", "disabled");
       });

 replace above code with below

// if checked.
$('input[type=checkbox][id*=Chad]').on('ifChecked', function (event) {
    $("#Txtmatn").removeAttr("disabled");
    $("#Txtmatn").removeAttr('readonly');
    $("#Txtmatn").focus();
});
// if uncheckd.
$('input[type=checkbox][id*=Chad]').on('ifUnchecked', function (event) {
    $("#Txtmatn").attr('readonly', 'readonly');
});

and if you dont want to use ReadOnly Property then you need to make use of Ajax Call like below

$('[id*=YourSavingButtonId]').click(function () {
    alert($("#Txtmatn").val());
    //your ajax call comes here.
    return false;
});

for more details on Ajax Calling refer below article

Send (Pass) multiple parameters to WebMethod in jQuery AJAX POST in ASP.Net