Question Text box value getting cleared in postback

Aashiqraja

New member
Joined
Oct 10, 2013
Messages
1
Programming Experience
5-10
Hi Friends,


Here i have one situation, like in my application i have one gridview with in this grid, i have textbox, dropdown list, and label controls.


problem :
I ll fill the sub commodity value based on the commodity, the commodity values are fetching when the grid data bound event. Everything is working as expected but my problem is based on the commodity and sub commodity i ll fetch the product id automatically, and there is one more option that is users can able to type and get the value like auto complete text box using java script. this also working as expected.


scenario 1: when i choose commodity and sub commodity the product id will automatically get value from the database if the id available or else it ll allow users to type and select the products from the list.


if the 1 row in the grid has the product id value (which means product id is available for the commodity and sub commodity) then the next row did't have the product id then user can able to select from the auto complete text box list. And the user can able to add the next row also as non mapped product id, like previous row.


in this way it works fine.


scenario 2: when i choose commodity and sub commodity the product id is not available in the list then the user have to select from the list. once he select on product id in the list then if he select the next row when he select the
sub commodity which is did't have the product id, then the previous row product id is also get cleared. I have check the methods. But i can't able to find where its get cleared.




Note :
to get the product id i am using the java script ajax method,

VB.NET:
   function GetProductNumber(ddlCommodityCode, ddlSubcode, index) {
            //debugger;
            $.ajax({
                url: "../AjaxWebServices/JSON.asmx/CheckInternalcommodity",
                dataType: "json",
                type: "POST",
                contentType: "application/Json; charset=utf-8",
                data: "{'MasterCommodity':'" + ddlCommodityCode + "','SubCommodity':'" + ddlSubcode + "'}",
                success: function (data) {
                    if (data.d != "") {
                        //alert("Success_" + data.d);                   
                        //document.getElementById("grdItems_ctl" + index + "_txtProduct").value = "";
                        document.getElementById("grdItems_ctl" + index + "_txtProduct").value = data.d;
                        document.getElementById("grdItems_ctl" + index + "_hdnSelectedProduct").value = data.d;
                        //document.getElementById("grdItems_ctl" + index + "_txtProduct").disabled = true;
                        document.getElementById("grdItems_ctl" + index + "_hdnSelectedProductNumber").value = data.d;
                        document.getElementById("grdItems_ctl" + index + "_txtProduct").readOnly = true; 
                    }
                    else {
                        // alert("Failure_" + data);  
                        //document.getElementById("grdItems_ctl" + index + "_txtProduct").value = "";
                        document.getElementById("grdItems_ctl" + index + "_txtProduct").value = data.d;                        
                        document.getElementById("grdItems_ctl" + index + "_hdnSelectedProduct").value = data.d;
                        document.getElementById("grdItems_ctl" + index + "_hdnSelectedProductNumber").value = data.d;
                        //document.getElementById("grdItems_ctl" + index + "_txtProduct").disabled = false;
                        document.getElementById("grdItems_ctl" + index + "_txtProduct").readOnly = false;
                    }
                },
                error: function () {
                    alert('failure');
                }
            });
        }

i m calling this method from the sub commodity change event.


This method is for auto complete text box method.

VB.NET:
$('input[id*="txtproduct"]').keyup(function () {
                //This function add the autocomplete functionality to all the Product fields in form
                AddProductAutoComplete();
            }); 


   function AddProductAutoComplete() {


                $('input[id*="txtproduct"]').keyup(function (event) {
                    $('#hdnproductField').val($(this).val());
                });


                $('input[id*="txtproduct"]').autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: "../AjaxWebServices/products.asmx/GetproductsLike",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            data: "{'value':'" + $('#hdnproductField').val() + "'}",
                            success: function (data) {
                                var json = jQuery.parseJSON(data.d);
                                response($.map(json, function (item) {
                                    return {
                                        label: productFormat(item.productNo, item.productDesc),
                                        value: item.productNo
                                    }
                                }));
                            }
                        });
                    },
                    minLength: 3,
                    delay: 500,
                    max: 50,
                    select: function (event, ui) {
                        var fieldname = '#' + $(this).attr('id').substring(0, $(this).attr('id').lastIndexOf("_") + 1) + 'hdnSelectedproduct';
                        var hdnSelectedproductNumber = '#' + $(this).attr('id').substring(0, $(this).attr('id').lastIndexOf("_") + 1) + 'hdnSelectedproductNumber';
                        var txtproductField = '#' + $(this).attr('id').substring(0, $(this).attr('id').lastIndexOf("_") + 1) + 'txtproduct';
                        $(fieldname).val(ui.item.value);                        
                        $(this).val(ui.item.label);
                        $(txtproductField).val(ui.item.label);
                        $(hdnSelectedproduct).val(ui.item.label);
                        ValidateproductString($(this).val(), fieldname);
                        return false;
                    },
                    open: function (event, ui) {
                        var fieldname = '#' + $(this).attr('id').substring(0, $(this).attr('id').lastIndexOf("_") + 1) + 'hdnSelectedproduct';                                          
                        ValidateproductString($(this).val(), fieldname);
                        return false;
                    },
                    close: function () {
                        return false;
                    },
                    focus: function () {
                        return false;
                    }
                })
            }

:upset: Could any help to find out this issue ,




Thanks & Regards
M.Asiq Raja
 
Back
Top