You must Sign In to post a response.
  • Category: ASP.NET

    Need detail about dropdownlist auto postback

    Dear Friends
    In my web based project i have one and i place one drop down and one text box. i was fill the drop down list with database value, now i want to get the drop down list value into textbox.

    here i try with below code

    <script type="text/javascript">
    function GetMasterDetails() {

    var value = document.getElementById('<%=ddlContractorGrade.ClientID%>');

    var getvalue = value.options[value.selectedIndex].value;
    var gettext = value.options[value.selectedIndex].text;
    // alert("value:-" + " " + getvalue + " " + "Text:-" + " " + gettext);

    document.getElementById('<%=txtTin0.ClientID%>').value = getvalue;


    }
    </script>

    -----------------------------------------
    my problem when i select the value in drop down list then
    i was press the tab control, now i got the value in textbox, but the dropdown automatically postback to the drop down 0 index value.

    Ex: i have 1 to 10 no in drop down. now i select 9 then press tab for move to the next control, when i was press the control that drop down get automatically postback.


    can any one guide friends
  • #763264

    Hi NavaneethKrishnan,

    If you are bind the dropdown in page load event and not is postback, obviously it is pointing 0 index for each post back, because you are binding the control again and again. If you want to maintain that selection state I request you to maintain the dropdown list index in one hidden field or any state control(viewstate) and assign that back to dropdown while binding time. This is the one of the way to maintain the selected index.


    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763268
    Check if you have set 'AutoPostback' property of the dropdownlist to 'true', then make it 'false'
    In that case you need to use javascript to collect dropdown value and fill it in your textbox
    see below snippet

    <script language="javascript">
    function setTextboxVal()
    {
    //get selected value from dropdownlist and set it in textbox
    document.getElementById("txtId").value = document.getElementById("dlstValue").value;
    }
    </script>

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763285
    Hi Naveen

    Dear Friends
    In my web based project i have one and i place one drop down and one text box. i was fill the drop down list with database value, now i want to get the drop down list value into textbox.

    here i try with below code

    <script type="text/javascript">
    function GetMasterDetails() {

    var value = document.getElementById('<%=ddlContractorGrade.ClientID%>');

    var getvalue = value.options[value.selectedIndex].value;
    var gettext = value.options[value.selectedIndex].text;
    // alert("value:-" + " " + getvalue + " " + "Text:-" + " " + gettext);

    document.getElementById('<%=txtTin0.ClientID%>').value = getvalue;


    }
    </script>

    -----------------------------------------
    my problem when i select the value in drop down list then
    i was press the tab control, now i got the value in textbox, but the dropdown automatically postback to the drop down 0 index value.

    Ex: i have 1 to 10 no in drop down. now i select 9 then press tab for move to the next control, when i was press the control that drop down get automatically postback.


    can you give a example for your reply.....

    Regards by
    Navaneetha krishnan
    Your idea should be improve my knowledge

  • #763344
    This will happen because of the postback.

    1. If any control triggers the event, the page will get post back.
    2. In the postback it will trigger the page load.
    3. If we are binding the values in the postback, It will reset and bind the the values again. So we will lose out selected values
    4. We can check the "IsPostback" in the page load. also we can use the Hidden fields to store the selected values

    By Nathan
    Direction is important than speed


Sign In to post your comments