Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

callback data to server side

Status
Not open for further replies.

abhi81

Programmer
Jan 13, 2007
18
0
0
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 GetStateByCountry(ByVal countryid As Integer) As String

'populate states
Dim conn As New SqlConnection(constr)
Dim sql As String
sql = "select state_abbv,state_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("slist").Rows
sb.Append(dr.Item("state_abbv").ToString)

sb.Append("^")
sb.Append(dr.Item("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 ReceiveServerData(rValue)
{

var ilen=document.getElementById('ctl00_ContentPlaceHolder1_cmbstate').options.length;

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

document.getElementById('ctl00_ContentPlaceHolder1_cmbstate').remove(j);
}



var rows=rValue.split("|");for (var i=0;i<rows.length-1;i++)
{

var value=rows.split("^");

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



option.innerHTML=value[1];document.getElementById('ctl00_ContentPlaceHolder1_cmbstate').appendChild(option);
}

document.getElementById('ctl00_ContentPlaceHolder1_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.........how can i make these values available on the sever side.

Thanks
 
>>how can i make these values available on the sever side
if you want to get only the selected values then you could do:
request.form(drpState.ClientId)

however if you want the entire list then you will have to set them into a hidden field and then get the values...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top