Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2007, 04:56 PM
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 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_ContentPlaceHo lder1_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[i].split("^");

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



option.innerHTML=value[1];document.getElementById('ctl00_ContentPlaceHolder 1_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
 
Old September 4th, 2007, 06:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii aranjan!!
view state is saved ,aspx page control is converted to equivalent html controls
and then page is loaded on the client side.

Since other fields performs the post back event,atleast page have some info abt the client side control's values,for that you need to store those values
i.e. you should put two html text boxes(say t1 and t2) without runat="server" where u can put the value of selected country and state select box.

now whenever user changes the country ,just put the equivalent value into the one textbox(t1) and whenever
state is changed on the client side put its value to(t2),
now on pageload event you can get the value of t1 and t2 and offcourse u can set those dropdown values too.

please let me know if you have other choice.

Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
javascript after server side code k.manisha ASP.NET 1.0 and 1.1 Professional 1 March 12th, 2007 06:28 PM
geocities allow server side code on their pages crmpicco Intro Programming 0 November 9th, 2005 10:31 AM
can you get window.opener data in server side code edmicman Javascript 3 August 27th, 2005 03:41 AM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.