I'm adding the VehicleDetails.VehicleMakeSelectedIndexChanged in the
OnPreRender event of the custom control.

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if
(!Page.ClientScript.IsClientScriptBlockRegistered("VehicleClientSideScript"))
            {
                CreateClientSideScript();
            }
        }

private void CreateClientSideScript()
{
sb.Append("function vehiclemakeindexchanged(vehicleMakeId)");
            sb.AppendLine();
            sb.Append("{");
            sb.AppendLine();
            sb.Append("\tvar modelDDL = document.getElementById('" +
((DropDownList)this.FindControl("VehicleModelDDL")).ClientID + "');");
            sb.AppendLine();
            sb.Append("\tvar yearDDL = document.getElementById('" +
((DropDownList)this.FindControl("ManufactureYearDDL")).ClientID +
"');");
            sb.AppendLine();
            sb.Append("\tvar fuelDDL = document.getElementById('" +
((DropDownList)this.FindControl("FuelTypeDDL")).ClientID + "');");
            sb.AppendLine();
            sb.Append("\tvar transDDL = document.getElementById('" +
((DropDownList)this.FindControl("TransmissionTypeDDL")).ClientID +
"');");
            sb.AppendLine();
            sb.Append("\tvar engineDDL = document.getElementById('" +
((DropDownList)this.FindControl("EngineSizeDDL")).ClientID + "');");
            sb.AppendLine();
            sb.Append("\tvar trimDDL = document.getElementById('" +
((DropDownList)this.FindControl("VehicleTrimDDL")).ClientID + "');");
            sb.AppendLine();
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(yearDDL, true);");
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(fuelDDL, true);");
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(transDDL, true);");
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(engineDDL, true);");
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(trimDDL, true);");
            sb.AppendLine();
            sb.AppendLine();
            sb.Append("\tif (vehicleMakeId > 0)");
            sb.AppendLine();
            sb.Append("\t{");
            sb.AppendLine();
            sb.Append("\t\tvar hidVehicleMake =
document.getElementById('" +
((HtmlInputHidden)this.FindControl("hidVehicleMake")).ClientID +
"');");
            sb.AppendLine();
            sb.Append("\t\thidVehicleMake.value = vehicleMakeId;");
            sb.AppendLine();
            sb.Append("\t\ttry {");
            sb.AppendLine();
            sb.Append("\t\tvar obj =
VehicleDetails.VehicleMakeSelectedIndexChanged(vehicleMakeId,
vehiclemakeindexchanged_callback);");
            sb.AppendLine();
            sb.Append("\t\t} catch (err) {");
            sb.AppendLine();
            sb.Append("\t\talert(err.toString()); }");
            sb.AppendLine();
            sb.Append("\t}");
            sb.AppendLine();
            sb.Append("\telse");
            sb.AppendLine();
            sb.Append("\t{");
            sb.AppendLine();
            sb.Append("\t\tremoveAllDDLOptions(modelDDL, true);");
            sb.AppendLine();
            sb.Append("\t}");
            sb.AppendLine();
            sb.Append("}");
            sb.AppendLine();
            sb.AppendLine();

            // This is the vehicle make call back method which gets
            // the response from the ajax method call and populates
            // the vehicle model drop down list
            sb.Append("function
vehiclemakeindexchanged_callback(response)");
            sb.AppendLine();
            sb.Append("{");
            sb.AppendLine();
            sb.Append("\tvar modelDDL = document.getElementById('" +
((DropDownList)this.FindControl("VehicleModelDDL")).ClientID + "');");
            sb.AppendLine();
            sb.Append("\tremoveAllDDLOptions(modelDDL, false);");
            sb.AppendLine();
            sb.Append("\tmodelDDL.options[0] = new Option('Please
select', '0', false, false);");
            sb.AppendLine();
            sb.Append("\tvar models = response.value;");
            sb.AppendLine();
            sb.AppendLine();
            sb.Append("\tfor (var i = 0; i <
models.Tables[0].Rows.length; i++)");
            sb.AppendLine();
            sb.Append("\t{");
            sb.AppendLine();
            sb.Append("\t\tmodelDDL.options[modelDDL.options.length] =
new Option(models.Tables[0].Rows[i][\"ModelDescription\"],
models.Tables[0].Rows[i][\"ModelDescription\"], false, false);");
            sb.AppendLine();
            sb.Append("\t}");
            sb.AppendLine();
            sb.Append("}");
            sb.AppendLine();
            sb.AppendLine();
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info/

Don't forget to read my blog at http://weblogs.asp.net/mschwarz/
-~----------~----~----~----~------~----~------~--~---

Reply via email to