|
Here's the HTML Tag That Calls the JavaScript Function
<asp:DropDownList id="ddlState" runat="server" Width="160px" TabIndex="13" DataTextField="Statename" DataValueField="Statecode" onChange="return jsState()"></asp:DropDownList>
Here's the JavaScript Code That Calls the pageMethods
<!-- jsState -->
<script type="text/javascript">
function jsState()
{
var State = document.getElementById("<%=ddlState.ClientID%>");
document.getElementById("<%=hfselectedIndexState.ClientID%>").value = document.getElementById("<%=ddlState.ClientID%>").selectedIndex
if(State.options[State.selectedIndex].value == "-- Select State --")
{
document.getElementById("<%=ddlCity.ClientID%>").selectedIndex = 0;
document.getElementById("<%=ddlCity.ClientID%>").disabled = true;
}else
{
document.getElementById("<%=ddlCity.ClientID%>").disabled = false;
PageMethods.GetCity(State.options[State.selectedIndex].value,onSuccess_GetCity, onFailed_GetCity);
}
}
function onSuccess_GetCity(value, ctx, methodName) {
ClearOption(document.getElementById("<%=ddlCity.ClientID%>"));
var i = 1
for(prop in value.rows)
{
addOption(document.getElementById("<%=ddlCity.ClientID%>"),value.rows[prop].CITYNAME,value.rows[prop].CITYCODE);
if(value.rows[prop].CITYCODE == document.getElementById("<%=hfCity.ClientID%>").value)
document.getElementById("<%=hfselectedIndexCity.ClientID%>").value = i;
i = i + 1;
}
if(bCity == true)
document.getElementById("<%=ddlCity.ClientID%>").selectedIndex = document.getElementById("<%=hfselectedIndexCity.ClientID%>").value
bCity=false;
}
function onFailed_GetCity(ex, ctx, methodName) {
alert(ex.get_exceptionType());
// get_stackTrace(), get_message(),
// get_statusCode(), get_timedOut()
}
</script>
Heres's the WebService Function That Return The Dataset
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetCity(ByVal StateCode As String) As DataTable
Dim oDataSet As New DataSet
Dim oCity As New cCity
oCity.STATECODE = StateCode
oDataSet = oCity.GetData
Return oDataSet.Tables(0)
End
Web.Config Please do this if you get an exception
I spend a loat of time trying to figure out how to solve this problem of returning a dataset
from a Ajx WebMethod PageMethods Tried differnt things finally figured out its a simple
uncommeting of the following tags or adding these lines to web,config.
<jsonSerialization maxJsonLength="500">
<converters>
<add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter,
Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter
, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter,
Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</converters>
</jsonSerialization>
|