callback data to server side code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhi81
    New Member
    • Dec 2006
    • 3

    #1

    callback data to server side code

    Hello All,

    I implemented a callback on page. So basically this is what is happening during the page load i populate 2 dropdowns 1 for country and one for state based on the default values for country and state stored in the web.config. Both of them are being populated from a database. Every time the country is changed the new set of states is loaded from the databse based on the country. I am doing this using the callback feature. The callback function is as follows:

    Private Function GetStateByCount ry(ByVal countryid As Integer) As String

    'populate states
    Dim conn As New SqlConnection(c onstr)
    Dim sql As String
    sql = "select state_abbv,stat e_name from ei_state where country_id=" & countryid
    Dim adap As New SqlDataAdapter( sql, conn)
    Dim ds As New DataSet
    adap.Fill(ds, "slist")
    Dim dr As DataRow
    Dim sb As New StringBuilder

    For Each dr In ds.Tables("slis t").Rows
    sb.Append(dr.It em("state_abbv" ).ToString)

    sb.Append("^")
    sb.Append(dr.It em("state_name" ).ToString)

    sb.Append("|")
    Next

    ds.Dispose()
    adap.Dispose()
    conn.Close()
    Return sb.ToString
    End Function

    This returns the string to the javascript handling the callback which is as follows:

    function ReceiveServerDa ta(rValue)
    {

    var ilen=document.g etElementById(' ctl00_ContentPl aceHolder1_cmbs tate').options. length;

    for (var j=ilen-1;j>=0;j--)
    {

    document.getEle mentById('ctl00 _ContentPlaceHo lder1_cmbstate' ).remove(j);
    }



    var rows=rValue.spl it("|");for (var i=0;i<rows.leng th-1;i++)
    {

    var value=rows[i].split("^");

    var option=document .createElement( "OPTION");
    option.value=va lue[0];



    option.innerHTM L=value[1];document.getEl ementById('ctl0 0_ContentPlaceH older1_cmbstate ').appendChild( option);
    }

    document.getEle mentById('ctl00 _ContentPlaceHo lder1_cmbstate' ).style.width=" 215";
    }

    Everything works as desired however when i do my postback to submit the data from this form which has other fields like addres, city, etc. to the database it saves everything from all the other fields but the state value is saved as a null string.

    I know the reason behind it, reason being that the new set of values is generated on the client side.........ho w can i make these values available on the sever side.

    Thanks
Working...